-
Notifications
You must be signed in to change notification settings - Fork 194
/
Copy pathserver.go
46 lines (37 loc) · 846 Bytes
/
server.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
37
38
39
40
41
42
43
44
45
46
package main
import (
"flag"
"log"
"strconv"
"github.com/Allenxuxu/gev"
)
type example struct{}
func (s *example) OnConnect(c *gev.Connection) {
log.Println(" OnConnect : ", c.PeerAddr())
}
func (s *example) OnMessage(c *gev.Connection, ctx interface{}, data []byte) (out interface{}) {
log.Println("OnMessage:", data)
out = data
return
}
func (s *example) OnClose(c *gev.Connection) {
log.Println("OnClose")
}
func main() {
handler := new(example)
var port int
var loops int
flag.IntVar(&port, "port", 1833, "server port")
flag.IntVar(&loops, "loops", -1, "num loops")
flag.Parse()
s, err := gev.NewServer(handler,
gev.Network("tcp"),
gev.Address(":"+strconv.Itoa(port)),
gev.NumLoops(loops),
gev.CustomProtocol(&ExampleProtocol{}))
if err != nil {
panic(err)
}
log.Println("server start")
s.Start()
}