Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

An easy-to-use event-based networking library based on KCP and Smux for Go.

License

NotificationsYou must be signed in to change notification settings

zeozeozeo/jolta

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Report CardLicenseDocumentation

This is an event-based networking library for Go, based onKCP andSmux.

Features

  • Secure: all of the data is encrypted by default, and there's no way to disable it.
  • Small latency: the KCP protocol isdesigned for small latencies.
  • Small: the entire library is ~650 lines of code.

Examples

(Server) Start a server

package mainimport"github.com/zeozeozeo/jolta"funcmain() {// server address, password, saltserver:=jolta.NewServer("127.0.0.1:7145", []byte("test password"), []byte("test salt"))// listen (this is blocking)iferr:=server.Listen();err!=nil {panic(err)}}

(Client) Connect to a server

package mainimport"github.com/zeozeozeo/jolta"funcmain() {// server address, password and salt// of the server you want to connect toclient:=jolta.NewClient("127.0.0.1:7145", []byte("test password"), []byte("test salt"))// connect to the server (this is blocking)iferr:=client.Connect();err!=nil {panic(err)}}

(Client) Send and recieve messages to/from other clients

funcmain() {// client := jolta.NewClient(...)client.OnConnect(func(client*jolta.Client) {// send a message to all connected// clients, the event name can be// any stringclient.SendAll("any event name", []byte("hello from client!"))// get all clients connected to// the serverclients,err:=client.GetClients()iferr!=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 clientsclient.On("any event name",func(client*jolta.Client,senderIduint32,data []byte) {// do anything you want...fmt.Printf("client %d says: %s\n",senderId,string(data))})// client.Connect()...}

See more examples ininternal/examples

About

An easy-to-use event-based networking library based on KCP and Smux for Go.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp