加入网络层
This commit is contained in:
33
Server/common/net/socket/server.go
Normal file
33
Server/common/net/socket/server.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package socket
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Action int
|
||||
|
||||
const (
|
||||
// None indicates that no action should occur following an event.
|
||||
None Action = iota
|
||||
// Close closes the connection.
|
||||
Close
|
||||
// Shutdown shutdowns the engine.
|
||||
Shutdown
|
||||
)
|
||||
|
||||
// ISocketServer 由应用层实现
|
||||
type ISocketServer interface {
|
||||
OnOpen(ISocketConn) ([]byte, Action) // 开启连接
|
||||
OnHandShake(ISocketConn) // 开始握手
|
||||
OnMessage(ISocketConn, []byte) Action // 收到消息
|
||||
OnClose(ISocketConn, error) Action // 关闭连接
|
||||
OnTick() (time.Duration, Action)
|
||||
}
|
||||
|
||||
// ISocketConn 由网络层实现
|
||||
type ISocketConn interface {
|
||||
GetParam(key string) interface{}
|
||||
SetParam(key string, values interface{})
|
||||
Write(data []byte) error
|
||||
Close() error
|
||||
}
|
||||
Reference in New Issue
Block a user