Exemple #1
0
        protected static bool OnEchoOk(TestClientSocket socket, CodedInputStream stream)
        {
            CsEchoOk proto   = CsEchoOk.Parser.ParseFrom(stream);
            string   message = proto.Message;

            Log.AddLog($"Received from server : {message}");

            return(true);
        }
Exemple #2
0
        public TestClientForm()
        {
            InitializeComponent();

            TestClientSocket.InitializePacketHandler();
            _tcpTestClient = new TcpTestClient();

            _logThread = new Thread(new ThreadStart(DisplayLog));
            _logThread.Start();
        }
Exemple #3
0
        public static void SendEchoRequest(TestClientSocket client, string message)
        {
            CsEchoRequest proto = new CsEchoRequest();

            proto.Message = message;

            Packet packet = new Packet();

            packet.EncodePacket(TcpServerCommand.CsEchoRequest, proto);
            client.Send(packet);
        }
Exemple #4
0
        private void ProcessConnect(SocketAsyncEventArgs e)
        {
            _testClientSocket = (TestClientSocket)e.UserToken;
            if (e.SocketError == SocketError.Success)
            {
                SocketAsyncEventArgs receiveEventArgs = new SocketAsyncEventArgs();
                receiveEventArgs.AcceptSocket = e.AcceptSocket;

                SocketAsyncEventArgs sendEventArgs = new SocketAsyncEventArgs();
                sendEventArgs.AcceptSocket = e.AcceptSocket;

                _testClientSocket.SetSocketAsyncEventArg(e.AcceptSocket, sendEventArgs, receiveEventArgs);
                _testClientSocket.OnConnected();
                _testClientSocket.StartReceive();

                e.AcceptSocket = null;
            }
            else
            {
                Log.AddLog($"connect failed - Message:{e.SocketError.ToString()}");
            }
        }
Exemple #5
0
        public bool Connect(string host, int port)
        {
            _connectEventArg            = new SocketAsyncEventArgs();
            _connectEventArg.Completed += new EventHandler <SocketAsyncEventArgs>(OnConnectCompleted);
            TestClientSocket testClientSocket = new TestClientSocket();

            _connectEventArg.UserToken = testClientSocket;

            _connectEventArg.RemoteEndPoint = GetServerEndpointUsingIpAddress(host, port);
            _connectEventArg.AcceptSocket   = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            //Post the connect operation on the socket.
            //A local port is assigned by the Windows OS during connect op.

            Log.AddLog($"Try to connect - host : {host} / Port : {port}");
            bool willRaiseEvent = _connectEventArg.AcceptSocket.ConnectAsync(_connectEventArg);

            if (!willRaiseEvent)
            {
                ProcessConnect(_connectEventArg);
            }

            return(true);
        }
Exemple #6
0
 protected static bool OnPingOk(TestClientSocket socket, CodedInputStream stream)
 {
     return(true);
 }