This commit is contained in:
crusader 2017-12-15 16:47:39 +09:00
parent d57710e28e
commit 11734b2eb5
3 changed files with 34 additions and 3 deletions

View File

@ -3,10 +3,13 @@ package client
import ( import (
crc "git.loafle.net/commons_go/rpc/client" crc "git.loafle.net/commons_go/rpc/client"
crcrs "git.loafle.net/commons_go/rpc/client/rwc/socket" crcrs "git.loafle.net/commons_go/rpc/client/rwc/socket"
csc "git.loafle.net/commons_go/server/client" crr "git.loafle.net/commons_go/rpc/registry"
) )
func New(addr string, clientHandler ClientHandler, socketHandler csc.SocketHandler) crc.Client { func New(addr string, rpcInvoker crr.RPCInvoker) crc.Client {
clientHandler := newClientHandler(rpcInvoker)
socketHandler := newSocketHandler()
socketBuilder := NewSocketBuilder(addr, socketHandler) socketBuilder := NewSocketBuilder(addr, socketHandler)
cRWCHandler := crcrs.New(socketBuilder) cRWCHandler := crcrs.New(socketBuilder)

View File

@ -6,7 +6,7 @@ import (
crr "git.loafle.net/commons_go/rpc/registry" crr "git.loafle.net/commons_go/rpc/registry"
) )
func NewClientHandler(rpcInvoker crr.RPCInvoker) ClientHandler { func newClientHandler(rpcInvoker crr.RPCInvoker) ClientHandler {
ch := &ClientHandlers{} ch := &ClientHandlers{}
ch.RPCInvoker = rpcInvoker ch.RPCInvoker = rpcInvoker
ch.Codec = json.NewClientCodec() ch.Codec = json.NewClientCodec()

28
client/socket_handlers.go Normal file
View File

@ -0,0 +1,28 @@
package client
import (
"net"
csc "git.loafle.net/commons_go/server/client"
)
type SocketHandlers struct {
csc.SocketHandlers
}
func (sh *SocketHandlers) OnConnect(socketContext csc.SocketContext, conn net.Conn) {
sh.SocketHandlers.OnConnect(socketContext, conn)
}
func (sh *SocketHandlers) OnDisconnect(soc csc.Socket) {
sh.SocketHandlers.OnDisconnect(soc)
}
func (sh *SocketHandlers) Validate() {
sh.SocketHandlers.Validate()
}
func newSocketHandler() csc.SocketHandler {
return &SocketHandlers{}
}