Skip to content

zengjiwen/gamenet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gamenet

efficient and clear game net lib

feature

  1. TCP
  2. using pool for reducing memory alloc
  3. graceful shutdown
  4. flush delay option
  5. user data
  6. support actor and csp mode
  7. rate limit

in developing...

example:

package main

import (
	"fmt"
	"github.com/zengjiwen/gamenet"
	"github.com/zengjiwen/gamenet/server"
	"os"
	"os/signal"
)

func main() {
	eventChan := make(chan func())
	tcpServer := server.NewServer("tcp", "0.0.0.0:0", echoHandler{},
		server.WithEventChan(eventChan))
	go tcpServer.ListenAndServe()

	go func() {
		for event := range eventChan {
			event()
		}
	}()

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)
	<-c
	tcpServer.Shutdown()
}

type echoHandler struct {
}

func (eh echoHandler) OnNewConn(c gamenet.Conn) {
	fmt.Println("OnNewConn")
}

func (eh echoHandler) OnConnClosed(c gamenet.Conn) {
	fmt.Println("OnConnClosed")
}

func (eh echoHandler) OnRecvData(c gamenet.Conn, data []byte) {
	fmt.Printf("OnRecvData: %s", data)
	c.Send(data)
}

About

game net lib

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages