Beispiel #1
0
        public void OnReceived(IAsyncResult ar)
        {
            try
            {
                IPEndPoint sender       = new IPEndPoint(IPAddress.Any, 0);
                EndPoint   tempRemoteEP = (EndPoint)sender;

                int size = _server.EndReceiveFrom(ar, ref tempRemoteEP);

                if (size > 0)
                {
                    int position = 0;


                    byte[] buffer = new byte[_server.ReceiveBufferSize];
                    Buffer.BlockCopy(_buffer, position, buffer, 0, size);
                    ConReader reader = new ConReader(buffer);

                    Console.WriteLine(teste + "- POSITION =" + position + " size = " + size);

                    UDPClient client = new UDPClient(_server, tempRemoteEP);
                    _onReceivedHandler(client, reader);
                    position += reader.GetSize();
                }
                _server.BeginReceiveFrom(_buffer, 0, _server.ReceiveBufferSize, SocketFlags.None, ref _endPoint, new AsyncCallback(OnReceived), null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Fechando conexao : " + e.StackTrace);
            }
        }
        private void OnReceived(IAsyncResult ar)
        {
            EndPoint endPoint = new IPEndPoint(_ipAddress, _port);
            int      size     = _server.EndReceiveFrom(ar, ref endPoint);

            if (size > 0)
            {
                int position = 0;

                byte[] buffer = new byte[_server.ReceiveBufferSize];
                Buffer.BlockCopy(_buffer, position, buffer, 0, size);

                ConReader reader = new ConReader(buffer);

                Console.WriteLine(teste + "- POSITION =" + position + " size = " + size);

                _onReceivedHandler(reader);
                position += reader.GetSize();

                teste++;
            }
            _server.BeginReceiveFrom(_buffer, 0, _server.ReceiveBufferSize, SocketFlags.None, ref _endPoint, new AsyncCallback(OnReceived), null);
        }
Beispiel #3
0
        private void OnReceived(IAsyncResult ar)
        {
            int size = _server.EndReceive(ar);

            if (size > 0)
            {
                int position = 0;
                while (size > position)
                {
                    byte[] buffer = new byte[_server.ReceiveBufferSize];
                    Buffer.BlockCopy(_buffer, position, buffer, 0, size);

                    ConReader reader = new ConReader(buffer);

                    Console.WriteLine(teste + "- POSITION =" + position + " size = " + size);

                    _onReceivedHandler(reader);
                    position += reader.GetSize();
                }
                teste++;

                _server.BeginReceive(_buffer, 0, _server.ReceiveBufferSize, SocketFlags.None, new AsyncCallback(OnReceived), null);
            }
        }