Пример #1
0
 static public void Register(PackageTranslator target)
 {
     
     target.RegisterMessage(Protocol.sendLogin, Create_sendLoginVO);
 
     target.RegisterMessage(Protocol.testCommonStruct, Create_testCommonStructVO);
 
     target.RegisterMessage(Protocol.sendString, Create_sendStringVO);
 
 }
Пример #2
0
        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);
                }

            }


        }
Пример #3
0
 static public PackageTranslator GetTranslator()
 {
     var translator = new PackageTranslator();
     Register(translator);
     return translator;
 }
Пример #4
0
 public RPCServer(TestServer server, PackageTranslator translator)
 {
     this.server = server;
     this.translator = translator;
     server.OnData += OnData;
 }
Пример #5
0
 public RPCClient(BaseConnection connection, PackageTranslator packager)
 {
     this.connection = connection;
     this.packager = packager;
 }