Ejemplo n.º 1
0
        public void StartAsync(int Port, bool restartOnFail = false)
        {
            AsyncServer = new AsyncTask(() => {
                Start(Port);
            });
            AsyncServer.AddAfterFinishJob(() => {
                this.AsyncServer = null;
            });

            AsyncServer.SetName("ServerHolder:" + Port.ToString());
            AsyncServer.Start(false);
        }
Ejemplo n.º 2
0
        private void HandleConnection(MediaConnectionInstance sck)
        {
            bool autoClose = AutoClose;

            sck.Disposed += sck_Disposed;
            AsyncTask task = new AsyncTask(() => {
                if (OnHandleConnection != null)
                {
                    OnHandleConnectionEventArgs args = new OnHandleConnectionEventArgs(this, sck);
                    OnHandleConnection(this, args);
                }
            });

            if (autoClose)
            {
                task.AddAfterFinishJob(() =>
                {
                    try
                    {
                        //Console.WriteLine("Disconnect {0} (PID:{1}) (Second Connection?{2})", sck.IPAddress, sck.Attributes.GetAttributeInt("PID"), sck.Attributes.GetAttributeBool("IsSecondConnection"));
                        if (sck.RawConnection != null)
                        {
                            sck.RawConnection.Close();
                            sck.RawConnection.Dispose();
                        }
                    }
                    catch (Exception ee)
                    {
                        Console.WriteLine(ee.ToString());
                    }
                    mLocker.Synchronized(() =>
                    {
                        mServers.Remove(sck);
                    });
                    if (OnServerRemoved != null)
                    {
                        OnServerRemoved(this, new OnHandleConnectionEventArgs(this, sck));
                    }
                });
            }
            task.Start(false);
        }