Exemplo n.º 1
0
        public async void Connect(String host, int port)
        {
            Host = host;
            Port = port;

            logger.Debug($"Connecting to {Host}:{Port}");
            await TcpClient.ConnectAsync(host, port);

            var args = new TcpSocketEventArgs <TOpcode> {
                TcpClient = this
            };

            if (TcpClient.Connected)
            {
                logger.Debug($"Connected to {Host}:{Port}");
                TcpClient.GetStream().ReadTimeout = 1000;
                OnConnected?.Invoke(this, args);
            }
            else
            {
                logger.Debug($"Connect failed to {Host}:{Port}");
                OnConnectFailed?.Invoke(this, args);
            }

            ReadAsync();
        }
 protected override void Initialize()
 {
     RegisterAllDevices();
     if (ether?.Connect() ?? false)
     {
         ThreadPool.QueueUserWorkItem(new WaitCallback((object callback) => { OnConnected?.Invoke(this); }));
         ether.OnPacketReceived += Ether_OnPacketReceived;
     }
     else
     {
         ThreadPool.QueueUserWorkItem(new WaitCallback((object callback) => { OnConnectFailed?.Invoke(); }));
     }
 }
Exemplo n.º 3
0
        internal void ConnectHandler(CallingEventParams eventParams, CallingEventParams.ConnectParams connectParams)
        {
            OnConnectStateChange?.Invoke(mAPI, this, eventParams, connectParams);

            switch (connectParams.State)
            {
            case CallConnectState.failed:
                OnConnectFailed?.Invoke(mAPI, this, eventParams, connectParams);
                break;

            case CallConnectState.connecting:
                OnConnectConnecting?.Invoke(mAPI, this, eventParams, connectParams);
                break;

            case CallConnectState.connected:
                if (Peer != null)
                {
                    mLogger.LogWarning("Received ConnectParams for Call that is already connected to a Peer");
                    return;
                }
                Call peer = mAPI.GetCall(connectParams.Peer.CallID);
                if (peer == null)
                {
                    mLogger.LogWarning("Received ConnectParams with unknown Peer.CallID: {0}", connectParams.Peer.CallID);
                    return;
                }
                Peer      = peer;
                peer.Peer = this;
                OnConnectConnected?.Invoke(mAPI, this, peer, eventParams, connectParams);
                break;

            case CallConnectState.disconnected:
                OnConnectDisconnected?.Invoke(mAPI, this, eventParams, connectParams);
                break;
            }
        }
		private void Invoke_OnConnectFailed(ConnectFailedReason reason)
		{
			_eventQueue.Add(() => OnConnectFailed?.Invoke(reason));
		}
 private void Conn_OnConnectFailed(ConnectFailedReason reason)
 {
     OnConnectFailed?.Invoke(reason);
 }