Beispiel #1
0
 public bool connect(string ipaddr, int port, System.AsyncCallback callback)
 {
     // if (!Socket_.IsWorking_)
     Socket_.Init(ipaddr, port);
     Socket_Callback = callback;
     disconnect();
     return(Socket_.Connect(ipaddr, port));
 }
        public ConnectionResult InitServer(string bindAddress, uint listenPort)
        {
            if (_mode != ManagerMode.NotDefined)
            {
                return(ConnectionResult.AlreadyInitialized);
            }

            _listenSocket = new SocketWrapper();
            var res = _listenSocket.Init();

            if (res != SocketResultCode.OK)
            {
                _listenSocket = null;
                return(Converter.SockResToConnRes(res));
            }

            _mode = ManagerMode.Server;
            _listenSocket.Connected       += OnListenSocketConnected;
            _listenSocket.ConnectionError += OnListenSocketConnectionError;

            res = _listenSocket.StartListen(bindAddress, (int)listenPort);
            if (res != SocketResultCode.OK)
            {
                if (res == SocketResultCode.BindFailed || res == SocketResultCode.ListenFailed)
                {
                    res = _listenSocket.LastSocketError;
                }
                _listenSocket.Remove();
                _listenSocket = null;
                return(Converter.SockResToConnRes(res));
            }

            _serverAddress = bindAddress;
            _serverPort    = listenPort;
            return(ConnectionResult.OK);
        }