예제 #1
0
        private void Disconnect()
        {
            Instances.Disconnect();

            endPoint = null;
            socket   = null;
        }
예제 #2
0
        private void DisConnect()
        {
            Instances.Disconnect();

            stream         = null;
            packet         = null;
            receviceBuffer = null;
            socket         = null;
        }
예제 #3
0
        private void ReceivceCallBacks(IAsyncResult result)
        {
            try
            {
                byte[] _data = socket.EndReceive(result, ref endPoint);
                socket.BeginReceive(ReceivceCallBacks, null);

                if (_data.Length < 4)
                {
                    Instances.Disconnect();
                    return;
                }

                HandleData(_data);
            }
            catch (Exception e)
            {
                Disconnect();
            }
        }
예제 #4
0
        private void ReceviceCallBack(IAsyncResult result)
        {
            try
            {
                int _byteLength = stream.EndRead(result);
                if (_byteLength <= 0)
                {
                    Instances.Disconnect();                                                                                 // only close socket
                    return;
                }

                byte[] _data = new byte[_byteLength];
                Array.Copy(receviceBuffer, _data, _byteLength);

                packet.Reset(HandleData(_data));
                stream.BeginRead(receviceBuffer, 0, dataBufferSize, ReceviceCallBack, null);                                 // loop throw
            }
            catch (Exception e)
            {
                DisConnect();
                Console.WriteLine($"Error Receiving Data :{ e }");
            }
        }