https://github.com/zeozeozeo/jolta
An easy-to-use event-based networking library based on KCP and Smux for Go.
https://github.com/zeozeozeo/jolta
easy-to-use event-based event-driven golang kcp networking smux
Last synced: 3 months ago
JSON representation
An easy-to-use event-based networking library based on KCP and Smux for Go.
- Host: GitHub
- URL: https://github.com/zeozeozeo/jolta
- Owner: zeozeozeo
- License: unlicense
- Created: 2022-11-22T13:45:34.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-22T13:58:00.000Z (over 2 years ago)
- Last Synced: 2025-01-31T19:39:59.663Z (5 months ago)
- Topics: easy-to-use, event-based, event-driven, golang, kcp, networking, smux
- Language: Go
- Homepage: https://pkg.go.dev/github.com/zeozeozeo/jolta
- Size: 10.7 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Jolta
[](https://goreportcard.com/report/github.com/zeozeozeo/jolta)

[](https://pkg.go.dev/github.com/zeozeozeo/jolta)This is an event-based networking library for Go, based on [KCP](https://github.com/xtaci/kcp-go) and [Smux](https://github.com/xtaci/smux).
# Features
- Secure: all of the data is encrypted by default, and there's no way to disable it.
- Small latency: the KCP protocol is [designed for small latencies](https://raw.githubusercontent.com/skywind3000/kcp/master/images/spatialos-50.png).
- Small: the entire library is ~650 lines of code.# Examples
## (Server) Start a server
```go
package mainimport "github.com/zeozeozeo/jolta"
func main() {
// server address, password, salt
server := jolta.NewServer("127.0.0.1:7145", []byte("test password"), []byte("test salt"))// listen (this is blocking)
if err := server.Listen(); err != nil {
panic(err)
}
}
```## (Client) Connect to a server
```go
package mainimport "github.com/zeozeozeo/jolta"
func main() {
// server address, password and salt
// of the server you want to connect to
client := jolta.NewClient("127.0.0.1:7145", []byte("test password"), []byte("test salt"))// connect to the server (this is blocking)
if err := client.Connect(); err != nil {
panic(err)
}
}
```## (Client) Send and recieve messages to/from other clients
```go
func main() {
// client := jolta.NewClient(...)client.OnConnect(func(client *jolta.Client) {
// send a message to all connected
// clients, the event name can be
// any string
client.SendAll("any event name", []byte("hello from client!"))// get all clients connected to
// the server
clients, err := client.GetClients()
if err != nil || len(clients) == 0 {
return
}// send a message to some client
// (clients are represented with
// ID's, 1 being the client that
// connected first)
client.SendTo("any event name", clients[0], []byte("hi client!"))
})// recieve messages from other clients
client.On("any event name", func(client *jolta.Client, senderId uint32, data []byte) {
// do anything you want...
fmt.Printf("client %d says: %s\n", senderId, string(data))
})// client.Connect()...
}
```## See more examples in [internal/examples](https://github.com/zeozeozeo/jolta/tree/main/internal/examples)