-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
37 lines (35 loc) · 915 Bytes
/
main.go
File metadata and controls
37 lines (35 loc) · 915 Bytes
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
37
package main
import (
"github.com/Li-giegie/node"
"github.com/Li-giegie/node/pkg/conn"
"github.com/Li-giegie/node/pkg/message"
"github.com/Li-giegie/node/pkg/reply"
"github.com/Li-giegie/node/pkg/server"
"log"
"net"
)
func main() {
srv := node.NewServerOption(1)
server.OnAccept(func(conn net.Conn) (next bool) {
log.Println("OnAccept", conn.RemoteAddr())
return true
})
server.OnConnect(func(conn *conn.Conn) (next bool) {
log.Println("OnConnect", conn.RemoteAddr())
return true
})
server.OnMessage(func(r *reply.Reply, m *message.Message) (next bool) {
log.Println("OnMessage", m.String())
r.String(message.StateCode_Success, "pong")
return true
})
server.OnClose(func(conn *conn.Conn, err error) (next bool) {
log.Println("OnClose", conn.RemoteAddr())
return true
})
log.Println("listen: 7890")
err := srv.ListenAndServe(":7890", nil)
if err != nil {
log.Fatal(err)
}
}