Пример #1
0
        private void StartReceiveUdp(Socket sender)
        {
            Task.Run(() =>
            {
                while (true)
                {
                    try
                    {
                        IPEndPoint remoteEndpoint = new IPEndPoint(IPAddress.Any, 0);
                        EndPoint remote = (EndPoint)remoteEndpoint;

                        byte[] bytes = new byte[short.MaxValue];
                        int messageLength = sender.ReceiveFrom(bytes,ref remote);

                        byte[] receivedBytes = bytes.Take(messageLength).ToArray();

                        STUNMessage stunMessage = new STUNMessage(receivedBytes);
                    }
                    catch (Exception ex)
                    {
                        ErrorOccurredEventArgs args = new ErrorOccurredEventArgs();
                        args.Exception = ex;
                        if (ErrorOccurred != null) ErrorOccurred(this, args);
                        Debug.WriteLine(ex.Message);
                        break;
                    }
                }
            });

        }
Пример #2
0
        private void StartReceiveTcp(Socket sender)
        {
            Task.Run(() =>
            {
                while (true)
                {
                    try
                    {
                        IPEndPoint senderEndpoint = new IPEndPoint(IPAddress.Any, 0);
                        //byte[] bytes = sender.Receive(ref senderEndpoint);

                        //STUNMessage stunMessage = new STUNMessage(bytes);
                    }
                    catch (Exception ex)
                    {
                        ErrorOccurredEventArgs args = new ErrorOccurredEventArgs();
                        args.Exception = ex;
                        if (ErrorOccurred != null) ErrorOccurred(this, args);
                        Debug.WriteLine(ex.Message);
                        break;
                    }
                }
            });

        }