Ejemplo n.º 1
0
        // Send
        public void Send(byte[] byteStream, DestinationTuple destination)
        {
            PacketDataSentEventArgs e = new PacketDataSentEventArgs(byteStream, destination);

            try
            {
                this.ConnectionSocket.SendTo(byteStream, SocketFlags.None, (EndPoint)destination.RemoteEndPoint);
                this.OnDataSent(e);
            }
            catch (ObjectDisposedException exception)
            {
                throw exception;
            }
            catch (SocketException exception)
            {
                if (exception.SocketErrorCode == SocketError.WouldBlock)
                {
                    this.ConnectionSocket.BeginSendTo(byteStream, 0, byteStream.Length, SocketFlags.None, (EndPoint)destination.RemoteEndPoint, new AsyncCallback(this.SentCallback), e);
                }
                else
                {
                    throw exception;
                }
            }
        }
Ejemplo n.º 2
0
        private void ReceivedCallback(IAsyncResult result)
        {
            SocketData s = (SocketData)result.AsyncState;

            try
            {
                if (s.Socket == null)
                {
                    return;
                }
                int        count = s.Socket.EndReceiveFrom(result, ref s.RemoteEndPoint);
                SocketData sd    = s;
                sd.TotalReadSize = count;
                sd.Buffer        = new byte[s.TotalReadSize];
                Array.Copy((Array)s.Buffer, (Array)sd.Buffer, sd.TotalReadSize);
                if (sd.TotalReadSize > 0)
                {
                    DestinationTuple            d = new DestinationTuple((IPEndPoint)sd.Socket.LocalEndPoint, (IPEndPoint)sd.RemoteEndPoint);
                    PacketDataReceivedEventArgs e = new PacketDataReceivedEventArgs(sd.TotalReadSize, sd.Buffer, d);
                    this.OnDataReceived(e);
                }
            }
            catch (Exception exception)
            {
            }
            StartReading();
        }
Ejemplo n.º 3
0
 // Constructor
 public UdpConnection()
 {
     try
     {
         dt = new DestinationTuple();
     }
     catch (Exception exception)
     {
         throw exception;
     }
 }