-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathclient.go
36 lines (27 loc) · 835 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"github.com/obsilp/rmnp"
"fmt"
)
func main() {
client := rmnp.NewClient("127.0.0.1:10001")
client.ServerConnect = serverConnect
client.ServerDisconnect = serverDisconnect
client.ServerTimeout = serverTimeout
client.PacketHandler = handleClientPacket
client.ConnectWithData([]byte{0, 1, 2})
select {}
}
func serverConnect(conn *rmnp.Connection, data []byte) {
fmt.Println("connected to server")
conn.SendReliableOrdered([]byte("ping"))
}
func serverDisconnect(conn *rmnp.Connection, data []byte) {
fmt.Println("disconnected from server:", string(data))
}
func serverTimeout(conn *rmnp.Connection, data []byte) {
fmt.Println("server timeout")
}
func handleClientPacket(conn *rmnp.Connection, data []byte, channel rmnp.Channel) {
fmt.Println("'" + string(data) + "'", "on channel", channel)
}