/// <summary>
        ///
        /// </summary>
        /// <param name="sipMessage"></param>
        /// <param name="destination"></param>
        public void Send(SipMessage sipMessage, DestinationTuple destination)
        {
            byte[] message         = sipMessage.GetBytes();
            CipDataSentEventArgs e = new CipDataSentEventArgs(message, destination);

            try {
                this.ConnectionSocket.SendTo(message, SocketFlags.None, (EndPoint)destination.RemoteEndPoint);
                this.OnDataSent(e);
            }
            catch (ObjectDisposedException ex)
            {
                throw ex;
            }
            catch (SocketException ex)
            {
                Console.WriteLine(ex.Message);
                if (ex.SocketErrorCode == SocketError.WouldBlock)
                {
                    this.ConnectionSocket.BeginSendTo(message, 0, message.Length, SocketFlags.None, (EndPoint)destination.RemoteEndPoint, new AsyncCallback(this.SentCallback), e);
                }
                else
                {
                    throw ex;
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="result"></param>
        private void ReceivedCallback(IAsyncResult result)
        {
            Console.WriteLine(this.server_name + " ReceivedCallback");

            SocketData s = (SocketData)result.AsyncState;

            try {
                if (s.Socket == null)
                {
                    Console.WriteLine("s.Socket is null");
                    return;
                }

                Console.WriteLine("s.Socket is good");

                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)
                {
                    Console.WriteLine("ReceivedCallback------sd.TotalReadSize:" + sd.Buffer.ToString());
                    DestinationTuple         d = new DestinationTuple((IPEndPoint)sd.Socket.LocalEndPoint, (IPEndPoint)sd.RemoteEndPoint);
                    CipDataReceivedEventArgs e = new CipDataReceivedEventArgs(sd.TotalReadSize, sd.Buffer, d);
                    this.OnDataReceived(e);
                }
            } catch (Exception ex) {
            }
            StartReading();
        }
 public CipDataReceivedEventArgs(int bufferSize, byte[] dataBuffer, DestinationTuple d)
 {
     TotalBytesRead = bufferSize;
     BytesRead      = new byte[bufferSize];
     Array.Copy(dataBuffer, 0, this.BytesRead, 0, bufferSize);
     DataRead         = encoding.GetString(BytesRead, 0, bufferSize);
     DestinationTuple = d;
 }
 public CipConnectionServer(MainForm frm)
 {
     try {
         dt       = new DestinationTuple();
         this.frm = frm;
     } catch (Exception ex) {
         throw ex;
     }
 }
        //private static UTF8Encoding encoding = new UTF8Encoding();

        public PacketDataReceivedEventArgs(int bufferSize, byte[] dataBuffer, DestinationTuple d)
        {
            TotalBytesRead = bufferSize;
            BytesRead      = new byte[bufferSize];
            Array.Copy(dataBuffer, 0, this.BytesRead, 0, bufferSize);
            DataRead = ByteStreamUtil.ByteToHexBit(BytesRead);
            //DataRead = encoding.GetString(BytesRead, 0, bufferSize);
            DestinationTuple = d;
        }
 public CipConnection(MainForm frm)
 {
     try {
         this.frm         = frm;
         dt               = new DestinationTuple();
         this.server_name = server_name;
     } catch (Exception ex) {
         throw ex;
     }
 }
Beispiel #7
0
 internal CipDataSentEventArgs(byte[] data, DestinationTuple recipient)
 {
     this.Destination = recipient;
     this.Data        = data;
 }
Beispiel #8
0
 public CipResponseEventArgs(SipResponse response, DestinationTuple d)
 {
     Response         = response;
     DestinationTuple = d;
 }