Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zac-garby/ezgnl
A server/client network library for games.
https://github.com/zac-garby/ezgnl
client game golang server
Last synced: about 2 months ago
JSON representation
A server/client network library for games.
- Host: GitHub
- URL: https://github.com/zac-garby/ezgnl
- Owner: zac-garby
- License: mit
- Created: 2017-12-15T20:23:53.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-12-16T12:20:10.000Z (about 7 years ago)
- Last Synced: 2024-10-30T06:27:45.022Z (3 months ago)
- Topics: client, game, golang, server
- Language: Go
- Size: 19.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ezgnl
⸻ Easy Game Networking Library
ezgnl is a networking library in Go suitable for making game servers/clients - or,
at least, it will be. It works as a generic networking library (a bit like socket.io),
but I've yet to add features useful for games. Things I'm planning on are:- Make UDP servers work
- Improved speed
- Listing local servers
- Rejection of connects from the server
- Kicking clients## An example
**The server**
```go
// A simple echo server
func main() {
s := server.New("8080")
defer s.Close()s.Accept(func(conn server.Conn, id server.UUID) {
conn.Handle("message", func(msg interface{}) {
log.Println("received message:", msg)conn.Send("reply", msg)
})conn.Disconnect(func(interface{}) {
log.Println("a user left")
})
})log.Println("listening...")
if err := s.Listen("tcp"); err != nil {
log.Println("listen:", err)
}
}```
**The client**
```go
// Sends a message to the echo server
func main() {
c := client.New("localhost:8080")
defer c.Close()c.Handle("reply", func(msg interface{}) {
log.Println("got reply:", msg)
})// Listen concurrently but still report errors
go func() {
if err := c.Listen("tcp"); err != nil {
log.Println("listen:", err)
}
}()c.Send("message", "hello, world!")
}
```As you can see, much easier than using the `net` package directly.
## Reserved message types
Some message types are reserved for internal use. You _can_ use them, but it's
probably not a good idea:- `disconnect`
- `ping`
- `pong`
- More might be added in the future