Beispiel #1
0
        public void Start()
        {
            try
            {
                _listener = SocketExt.CreateTcpSocket(AddressFamily.InterNetwork);
                _listener.Bind(EndPoint);
                _listener.Listen(DefaultBacktrace);
            }
            catch (Exception e)
            {
                OnError($"Server start failed, detail {e.Message} : {e.StackTrace}");
                return;
            }

            _acceptEvent            = new SocketAsyncEventArgs();
            _acceptEvent.Completed += OnAcceptCompleted;

            AcceptNext();
            Logger.Ins.Debug("Server started on {0}:{1}", Ip, Port);
        }
Beispiel #2
0
        public void Start()
        {
            if (!ParseAddress())
            {
                Loop.Ins.Perform(() => { OnError($"Parse address {Host}:{Port} failed."); });
                return;
            }

            if (string.IsNullOrEmpty(Host) || Port == 0)
            {
                throw new Exception("Address must be setted before start!");
            }

            _connectEvent            = new SocketAsyncEventArgs();
            _connectEvent.Completed += OnConnectCompleted;

            _underlineSocket = SocketExt.CreateTcpSocket(Address.AddressFamily);
            Connect();

            _stopped = false;
        }