private void _RecieveCallBack(IAsyncResult ar) { try { if (clientSocket == null) { LogHelper.ERRORLOG("clientsocket is null!"); } else if (!clientSocket.Connected) { LogHelper.ERRORLOG("clientsocket disconnected!"); } else { int count = clientSocket.EndReceive(ar); if (count == 0) { Close(); return; } msgHelper.AddCount(count); NetCmdHandle.Dispatch(msgHelper, this); Start(); } } catch (Exception e) { LogHelper.ERRORLOG(e); Close(); } }
public void Start() { NetCmdHandle.Init(); serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); serverSocket.Bind(IpEndpoint); serverSocket.Listen(0); serverSocket.BeginAccept(_AcceptCallBack, null); _SetServerState(ServerState.Running); }