Exemple #1
0
        private void SendData(object stateObject)
        {
            try
            {
                if (fPreviousPacket == null)
                {
                    fConnector.fSocket.Send(fData.Bytes, fData.Length, fData.ServerEndPoint);
                    fConnector.fBytesOut += fData.Length;
                }
                else
                {
                    fPreviousPacket.fDone.WaitOne();
                    if (!fCancel && !fPreviousPacket.fCancel)
                    {
                        fConnector.fSocket.Send(fData.Bytes, fData.Length, fData.ServerEndPoint);
                        fConnector.fBytesOut += fData.Length;
                    }
                    else
                    {
                        fCancel = true;
                    }
                }
            }
            catch (Exception ex)
            {
            }

            if (fPreviousPacket != null)
            {
                fPreviousPacket = null;
            }

            fDone.Set();
        }
Exemple #2
0
        public OutgoingUDPClientPacket(UDPConnector connector, DatagramPacket data, OutgoingUDPClientPacket previousPacket)
        {
            fConnector      = connector;
            fData           = data;
            fPreviousPacket = previousPacket;

            ThreadPool.QueueUserWorkItem(new WaitCallback(SendData));
        }
        public OutgoingUDPClientPacket(UDPConnector connector, DatagramPacket data, OutgoingUDPClientPacket previousPacket)
        {
            fConnector = connector;
            fData = data;
            fPreviousPacket = previousPacket;

            ThreadPool.QueueUserWorkItem(new WaitCallback(SendData));
        }
        private void SendData(object stateObject)
        {
            try
            {
                if (fPreviousPacket == null)
                {
                    fConnector.fSocket.Send(fData.Bytes, fData.Length, fData.ServerEndPoint);
                    fConnector.fBytesOut += fData.Length;
                }
                else
                {
                    fPreviousPacket.fDone.WaitOne();
                    if (!fCancel && !fPreviousPacket.fCancel)
                    {
                        fConnector.fSocket.Send(fData.Bytes, fData.Length, fData.ServerEndPoint);
                        fConnector.fBytesOut += fData.Length;
                    }
                    else
                    {
                        fCancel = true;
                    }
                }
            }
            catch (Exception ex)
            {
            }

            if (fPreviousPacket != null)
            {
                fPreviousPacket = null;
            }

            fDone.Set();
        }
Exemple #5
0
        /// <summary>
        /// Start the udp connector.
        /// </summary>
        public void Start()
        {
            if (!fActive)
            {
                try
                {
                    fActive = true;
                    try
                    {
                        fSocket = new UdpClient(0);
                    }
                    catch (SocketException ex)
                    {
                        fActive = false;
                        throw ex;
                    }

                    fLastIncomingPacket = null;
                    fLastOutgoingPacket = null;

                    if (fReadTimeOut > 0)
                    {
                        /*fSocket.SendTimeout = fReadTimeOut;
                        fSocket.ReceiveTimeout = fReadTimeOut;*/
                    }

                    try
                    {
                        fSocket.BeginReceive(new AsyncCallback(OnReceive), null);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                catch (SocketException ex)
                {
                    Stop();
                    throw ex;
                }
            }
        }
Exemple #6
0
 /// <summary>
 /// Send data to host.
 /// </summary>
 /// <param name="bytes">The byte array to be send.</param>
 /// <param name="offset">The position in the data buffer at witch to begin sending.</param>
 /// <param name="length">The number of the bytes to be send.</param>
 public void SendData(byte[] bytes, int offset, int length)
 {
     DatagramPacket outPacket = new DatagramPacket(bytes, offset, length, fServerEndPoint);
     fLastOutgoingPacket = new OutgoingUDPClientPacket(this, outPacket, fLastOutgoingPacket);
 }