public void Close() { FunctionsCommon.CloseAndNullSocket(ref tcpSocket); FunctionsCommon.CloseAndNullSocket(ref udpSocket); FunctionsCommon.CloseAndNullThread(ref listenTcpThread); FunctionsCommon.CloseAndNullThread(ref listenUdpThread); }
private void ListenTcp() { int ReceiveDataBytesCount; byte[] ReceiveDataBuffer; while (true) { try { ReceiveDataBuffer = new byte[1024]; using (MemoryStream memoryStream = new MemoryStream()) { do { ReceiveDataBytesCount = tcpSocket.Receive(ReceiveDataBuffer, ReceiveDataBuffer.Length, SocketFlags.None); memoryStream.Write(ReceiveDataBuffer, 0, ReceiveDataBytesCount); }while (tcpSocket.Available > 0); if (ReceiveDataBytesCount > 0) { ReceiveMessageEvent(messageSerializer.Deserialize(memoryStream.ToArray())); } } } catch (SocketException) { ClientDisconnectedEvent(this); FunctionsCommon.CloseAndNullSocket(ref tcpSocket); FunctionsCommon.CloseAndNullThread(ref listenTcpThread); } } }
public void DisconnectFromServer() { FunctionsCommon.CloseAndNullSocket(ref tcpSocket); FunctionsCommon.CloseAndNullThread(ref listenTcpThread); }