Ejemplo n.º 1
0
        /// <summary>
        /// Starts the transport.
        /// </summary>
        /// <param name="binding">The network binding the transport will use.</param>
        /// <param name="cbSocketBuffer">Size of the socket's send and receive buffers in bytes.</param>
        /// <param name="router">The <see cref="ISipMessageRouter" /> instance that will handle the routing of received messages.</param>
        /// <exception cref="SocketException">Thrown if there's a conflict with the requested and existing socket bindings.</exception>
        public void Start(NetworkBinding binding, int cbSocketBuffer, ISipMessageRouter router)
        {
            try
            {
                sock = new EnhancedSocket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                sock.SendBufferSize           = cbSocketBuffer;
                sock.ReceiveBufferSize        = cbSocketBuffer;
                sock.IgnoreUdpConnectionReset = true;
                sock.Bind(binding);

                this.localEP   = (IPEndPoint)sock.LocalEndPoint;
                this.onRecv    = new AsyncCallback(OnReceive);
                this.recvBuf   = new byte[64 * 1024];
                this.recvEP    = new IPEndPoint(IPAddress.Any, 0);
                this.router    = router;
                this.traceMode = SipTraceMode.None;

                recvPending = true;
                sock.BeginReceiveFrom(recvBuf, 0, recvBuf.Length, SocketFlags.None, ref recvEP, onRecv, null);
            }
            catch
            {
                if (sock.IsOpen)
                {
                    sock.Close();
                }

                sock = null;
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts the transport.
        /// </summary>
        /// <param name="binding">The network binding the transport will use.</param>
        /// <param name="cbSocketBuffer">Size of the socket's send and receive buffers in bytes.</param>
        /// <param name="router">The <see cref="ISipMessageRouter" /> instance that will handle the routing of received messages.</param>
        /// <exception cref="SocketException">Thrown if there's a conflict with the requested and existing socket bindings.</exception>
        public void Start(NetworkBinding binding, int cbSocketBuffer, ISipMessageRouter router)
        {
            this.cbSocketBuffer = cbSocketBuffer;
            this.listener       = new SocketListener();
            this.connections    = new Dictionary <string, Connection>();
            this.sweepInterval  = TimeSpan.FromSeconds(30);
            this.maxInactive    = TimeSpan.FromMinutes(5);     // Minimum time is 3 minutes according to RFC 3261
            this.router         = router;
            this.localEP        = binding;
            this.traceMode      = SipTraceMode.None;

            try
            {
                listener.SocketAcceptEvent += new SocketAcceptDelegate(OnAccept);
                listener.Start(binding, 100);
            }
            catch
            {
                listener.StopAll();
                listener = null;
            }
        }
Ejemplo n.º 3
0
 public void Initialize()
 {
     //NetTrace.Start();
     traceMode = SipTraceMode.Send;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Sets the diagnostic tracing mode.
 /// </summary>
 /// <param name="traceMode">The <see cref="SipTraceMode" /> flags.</param>
 public void SetTraceMode(SipTraceMode traceMode)
 {
     this.traceMode = traceMode;
 }