Example #1
0
 public void Close()
 {
     FunctionsCommon.CloseAndNullSocket(ref tcpSocket);
     FunctionsCommon.CloseAndNullSocket(ref udpSocket);
     FunctionsCommon.CloseAndNullThread(ref listenTcpThread);
     FunctionsCommon.CloseAndNullThread(ref listenUdpThread);
 }
Example #2
0
        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);
                }
            }
        }
Example #3
0
 public void DisconnectFromServer()
 {
     FunctionsCommon.CloseAndNullSocket(ref tcpSocket);
     FunctionsCommon.CloseAndNullThread(ref listenTcpThread);
 }