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); }
public TestClientForm() { InitializeComponent(); TestClientSocket.InitializePacketHandler(); _tcpTestClient = new TcpTestClient(); _logThread = new Thread(new ThreadStart(DisplayLog)); _logThread.Start(); }
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); }
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()}"); } }
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); }
protected static bool OnPingOk(TestClientSocket socket, CodedInputStream stream) { return(true); }