public RequestPlayers requestPlayers() { RequestPlayers request = new RequestPlayers(); request.send(); return(request); }
static void Main(string[] args) { server = new RPCServer(new TestServer(), new PackageTranslator(new ProtocolCenter())); ProtocolCenter.RegisterGlobalMessageHandler(globalHandler); ProtocolCenter.RegisterMessageHandler(MessageType.RequestSendString, doRequestSendString); ProtocolCenter.RegisterMessageHandler(MessageType.RequestPlayers, doRequestPlayers); RequestSendString.RegisterHandler(onRequestSendString); RequestPlayers.RegisterHandler(onRequestPlayers); server.StartListen(7666); Console.ReadLine(); }
public void start() { translator = new PackageTranslator(new ProtocolCenter()); connection = new SocketConnection("127.0.0.1", 7666); client = new RPCClient(connection, translator); ProtocolCenter.RegisterMessageHandler(MessageType.ResponseSendString, ResponseSendString); //client.RegisterMessageHandler(MessageType.ResponsePlayers, ResponsePlayers); ResponsePlayers.RegisterHandler(onResponsePlayers); ProtocolCenter.RegisterGlobalMessageHandler(globalMessageHandler); client.OnConnectSuccess += OnConnectSuccess; client.OnConnectFail += OnConnectFail; client.OnConnectClose += OnConnectClose; client.Connect(); /* connection.OnConnectSuccess += OnConnectSuccess; connection.OnData += OnData; connection.OnConnectClose += OnConnectClose; connection.Connect(); */ while (true) { var input = Console.ReadLine(); if (input.IndexOf("2") >= 0) { var msg = new RequestPlayers(); client.Call(msg); } else { var sendStr = new RequestSendString(); sendStr.content = input; client.Call(sendStr); } } }
static void onRequestPlayers(RequestPlayers vo) { Console.WriteLine("onRequestPlayers " + vo.customData); }