Ejemplo n.º 1
0
 // Methods
 private void Init(Socket socket, ConnectedHandler handler)
 {
     this.Socket = socket;
     Socket.ReceiveBufferSize = 1024 * 1024 * 100;
     Socket.SendBufferSize    = 1024 * 1024 * 100;
     this.OnConnected        += handler;
     this.OnConnected(this);
     byte[] buffer = new byte[4];
     Socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(receiveCommand), buffer);
 }
Ejemplo n.º 2
0
        public void TestConnected()
        {
            var connectedHandler = new ConnectedHandler();
            var msg = new MsgEventArgs {
                Command = "001", Data = new[] { "test" }
            };

            connectedHandler.Msg(Talker, Caller, msg);
            Assert.AreEqual("test", Talker.Nick);
        }
Ejemplo n.º 3
0
        private IEnumerator CheckConnectedHandler()
        {
            float startTime = Time.realtimeSinceStartup;

            while (true)
            {
                yield return(null);

                if (Connected)
                {
                    //_beatFailCount = 0;
                    _lastProtocolTime = Time.realtimeSinceStartup;
                    _reConnCount      = 0;
                    _gameServerErr    = false;
                    StopCoroutine("CheckConnStatus");
                    StartCoroutine("CheckConnStatus");
                    if (_reconnect)
                    {
                        ReConnLoginSucc();
                    }
                    if (connectedHandler != null)
                    {
                        connectedHandler(true);
                    }
                    yield break;
                }
                else
                {
                    float time = Time.realtimeSinceStartup - startTime;
                    if (time > 10)
                    {
                        if (!_reconnect)
                        {
                            DisConnect(true);
                            if (connectedHandler != null)
                            {
                                connectedHandler(false);
                            }
                            connectedHandler = null;
                        }
                        else if (/*_sendQueue.Count > 0 ||*/ _reConnSendQueue.Count > 0)
                        {
                            _reconnectable = true;
                        }
                        yield break;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private Task <bool> LoginAnon()
        {
            var tcs = new TaskCompletionSource <bool>();

            LoggedOnHandler    loggedOnCallback     = null;
            LogonFailedHandler logonFailedCallback  = null;
            ConnectedHandler   disconnectedCallback = null;

            loggedOnCallback     = () => { tcs.SetResult(true); onLoggedOn -= loggedOnCallback; onLogonFailed -= logonFailedCallback; onDisconnected -= disconnectedCallback; };
            logonFailedCallback  = (result) => { tcs.SetResult(false); onLogonFailed -= logonFailedCallback; onLoggedOn -= loggedOnCallback; onDisconnected -= disconnectedCallback; };
            disconnectedCallback = () => { tcs.SetResult(false); onDisconnected -= disconnectedCallback; onLoggedOn -= loggedOnCallback; onLogonFailed -= logonFailedCallback; };
            onLoggedOn          += loggedOnCallback;
            onLogonFailed       += logonFailedCallback;
            onDisconnected      += disconnectedCallback;

            DebugLog.WriteLine("Steam3Session", "Logging anonymously into Steam3...");
            steamUser.LogOnAnonymous();
            return(tcs.Task);
        }
Ejemplo n.º 5
0
        private IEnumerator CheckConnStatus()
        {
            WaitForSeconds wfs = new WaitForSeconds(2f);

            while (true)
            {
                yield return(wfs);

                if (_gameServerErr)
                {
                    DisConnect(true);
                    Debugger.LogError("服务器错误,断开连接,重新登陆");
                    if (connectedHandler != null)
                    {
                        connectedHandler(false);
                    }
                    yield break;
                }

                if (!Connected)
                {
                    if (_reConnCount == 0)
                    {
                        _reconnectable = true;
                    }
                    else if (_reConnCount > 3)
                    {
                        DisConnect(true);
                        if (connectedHandler != null)
                        {
                            connectedHandler(false);
                        }
                        connectedHandler = null;
                        Debugger.Log("连接服务器超时");
                        yield break;
                    }

                    Reconnect();
                }
            }
        }
Ejemplo n.º 6
0
        private Task <bool> Connect()
        {
            var tsc = new TaskCompletionSource <bool>();
            ConnectedHandler connectionAction = null, disconnectionAction = null;

            connectionAction    = () => { tsc.SetResult(true); onConnected -= connectionAction; onDisconnected -= disconnectionAction; };
            disconnectionAction = () => { tsc.SetResult(false); onDisconnected -= disconnectionAction; onConnected -= connectionAction; };
            onConnected        += connectionAction;
            onDisconnected     += disconnectionAction;

            bAborted                   = false;
            bConnected                 = false;
            bConnecting                = true;
            connectionBackoff          = 0;
            bExpectingDisconnectRemote = false;
            bDidDisconnect             = false;
            this.connectTime           = DateTime.Now;
            this.steamClient.Connect();

            return(tsc.Task);
        }
Ejemplo n.º 7
0
        public Task <bool> LoginAsAsync(SteamUser.LogOnDetails details)
        {
            TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();

            LoggedOnHandler    loggedOnCallback     = null;
            LogonFailedHandler logonFailedCallback  = null;
            ConnectedHandler   disconnectedCallback = null;

            loggedOnCallback     = () => { tcs.SetResult(true); onLoggedOn -= loggedOnCallback; onLogonFailed -= logonFailedCallback; onDisconnected -= disconnectedCallback; };
            logonFailedCallback  = (result) => { tcs.SetResult(false); onLogonFailed -= logonFailedCallback; onLoggedOn -= loggedOnCallback; onDisconnected -= disconnectedCallback; };
            disconnectedCallback = () => { tcs.SetResult(false); onDisconnected -= disconnectedCallback; onLoggedOn -= loggedOnCallback; onLogonFailed -= logonFailedCallback; };
            onLoggedOn          += loggedOnCallback;
            onLogonFailed       += logonFailedCallback;
            onDisconnected      += disconnectedCallback;

            SetLoginDetails(details);

            DebugLog.WriteLine("Steam3Session", "Connecting to Steam3...");

            Connect();

            return(tcs.Task);
        }
Ejemplo n.º 8
0
 public Connector(NetworkService networkService)
 {
     m_networkService    = networkService;
     m_connectedCallback = null;
 }
Ejemplo n.º 9
0
 public SocketConnecter(int Port)
 {
     this.port          = Port;
     callback_connected = null;
 }
Ejemplo n.º 10
0
 public Client(Socket socket, ConnectedHandler handler)
 {
     this.Init(socket, handler);
 }
 public void RaiseIsConnected()
 {
     ConnectedHandler?.Invoke(this, new EventArgs());
 }
Ejemplo n.º 12
0
 private void InitializeIrc()
 {
     //IdentService ident = new IdentService();
     Connected += new ConnectedHandler(Irc_Connected);
 }
Ejemplo n.º 13
0
 public CConnector(CNetworkService network_service)
 {
     this.network_service    = network_service;
     this.connected_callback = null;
 }
Ejemplo n.º 14
0
        public void TestOnlyTriggerOnConnected()
        {
            var connectedHandler = new ConnectedHandler();

            Assert.AreEqual("001", connectedHandler.ForCommand());
        }