7
7
"github.com/Allenxuxu/gev/log"
8
8
9
9
"github.com/Allenxuxu/gev"
10
- "github.com/Allenxuxu/gev/connection"
11
10
"github.com/Allenxuxu/gev/plugins/websocket"
12
11
"github.com/Allenxuxu/gev/plugins/websocket/ws"
13
12
)
@@ -18,11 +17,11 @@ type example struct {
18
17
// connection lifecycle
19
18
// OnConnect() -> OnRequest() -> OnHeader() -> OnMessage() -> OnClose()
20
19
21
- func (s * example ) OnConnect (c * connection .Connection ) {
20
+ func (s * example ) OnConnect (c * gev .Connection ) {
22
21
//log.Println("OnConnect: ", c.PeerAddr())
23
22
}
24
23
25
- func (s * example ) OnMessage (c * connection .Connection , data []byte ) (messageType ws.MessageType , out []byte ) {
24
+ func (s * example ) OnMessage (c * gev .Connection , data []byte ) (messageType ws.MessageType , out []byte ) {
26
25
//log.Println("OnMessage: ", string(data))
27
26
28
27
messageType = ws .MessageBinary
@@ -31,13 +30,13 @@ func (s *example) OnMessage(c *connection.Connection, data []byte) (messageType
31
30
return
32
31
}
33
32
34
- func (s * example ) OnClose (c * connection .Connection ) {
33
+ func (s * example ) OnClose (c * gev .Connection ) {
35
34
//log.Println("123 OnClose", c.PeerAddr())
36
35
}
37
36
38
37
// NewWebSocketServer 创建 WebSocket Server
39
38
func NewWebSocketServer (handler websocket.WSHandler , u * ws.Upgrader , opts ... gev.Option ) (server * gev.Server , err error ) {
40
- opts = append (opts , gev .Protocol (websocket .New (u )))
39
+ opts = append (opts , gev .CustomProtocol (websocket .New (u )))
41
40
return gev .NewServer (websocket .NewHandlerWrap (u , handler ), opts ... )
42
41
}
43
42
0 commit comments