Beispiel #1
0
    public bool Connect(string ip, int port)
    {
        if (connected)
        {
            return(ip == _ip && port == _port ? true : false);
        }

        try
        {
            _transport.Connect(ip, port);
            if (!_transport.IsConnected())
            {
                return(false);
            }

            _ip       = ip;
            _port     = port;
            connected = true;
        }
        catch (Exception e)
        {
            Debug.Log(e.ToString());
        }

        return(connected);
    }
        public async Task CreateTransport()
        {
            if (Logger.IsDebug)
            {
                Logger.Debug("Creating transport");
            }

            if (Transport != null)
            {
                (this as IConnectionContext).DestroyTransport();
            }

            try
            {
                var transport = GetTransportFactory().CreateTransport(await CreateTransportParameters());
                transport.Listener = this;
                Transport          = transport;
                Transport.Connect();
            }
            catch (Exception ex)
            {
                Logger.Error("Error while creating transport!. Message: " + ex.Message);
                if (ex is AblyException)
                {
                    throw;
                }

                throw new AblyException(ex);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Protocol negotiation finished successfully.
        /// </summary>
        private void OnNegotiationDataReceived(NegotiationData data)
        {
#if !BESTHTTP_DISABLE_WEBSOCKET
            if (data.TryWebSockets)
            {
                Transport = new WebSocketTransport(this);

                #if !BESTHTTP_DISABLE_SERVERSENT_EVENTS
                NextProtocolToTry = SupportedProtocols.ServerSentEvents;
                #else
                NextProtocolToTry = SupportedProtocols.HTTP;
                #endif
            }
            else
#endif
            {
                #if !BESTHTTP_DISABLE_SERVERSENT_EVENTS
                Transport = new ServerSentEventsTransport(this);

                // Long-Poll
                NextProtocolToTry = SupportedProtocols.HTTP;
                #else
                Transport = new PollingTransport(this);

                NextProtocolToTry = SupportedProtocols.Unknown;
                #endif
            }

            this.State = ConnectionStates.Connecting;
            TransportConnectionStartedAt = DateTime.UtcNow;

            Transport.Connect();
        }
Beispiel #4
0
        public async Task CreateTransport(string host)
        {
            if (Logger.IsDebug)
            {
                Logger.Debug("Creating transport");
            }

            if (Transport != null)
            {
                DestroyTransport();
            }

            try
            {
                var transport = GetTransportFactory().CreateTransport(await CreateTransportParameters(host));
                transport.Listener = this;
                Transport          = transport;
                Transport.Connect();
            }
            catch (Exception ex)
            {
                Logger.Error("Error while creating transport!.", ex.Message);
                if (ex is AblyException)
                {
                    throw;
                }

                throw new AblyException(new ErrorInfo("Error creating Socket Transport", ErrorCodes.ConnectionFailed, HttpStatusCode.ServiceUnavailable), ex);
            }
        }
Beispiel #5
0
        public bool Connect(string networkAddress, int networkPort)
        {
            clientNetStatistics = new ClientNetStatistics();
            if (IsConnected)
            {
                NetDebug.LogError("client is connected!");
                return(false);
            }
            if (ConnectState == NetConnectState.Connecting)
            {
                return(false);
            }
            SetNetConnectState(NetConnectState.Connecting);

            this.networkAddress = networkAddress;
            this.networkPort    = networkPort;
            NetDebug.Log("Client connecting to " + networkAddress + ":" + networkPort);

            if (Transport.Connect(networkAddress, networkPort))
            {
                return(true);
            }
            SetNetConnectState(NetConnectState.DisConnected);
            return(false);
        }
Beispiel #6
0
        private void OnNegotiationDataReceived(NegotiationData data)
        {
            int num = -1;

            for (int i = 0; i < ClientProtocols.Length; i++)
            {
                if (num != -1)
                {
                    break;
                }
                if (data.ProtocolVersion == ClientProtocols[i])
                {
                    num = i;
                }
            }
            if (num == -1)
            {
                num = 2;
                HTTPManager.Logger.Warning("SignalR Connection", "Unknown protocol version: " + data.ProtocolVersion);
            }
            Protocol = (ProtocolVersions)num;
            if (data.TryWebSockets)
            {
                Transport         = new WebSocketTransport(this);
                NextProtocolToTry = SupportedProtocols.ServerSentEvents;
            }
            else
            {
                Transport         = new ServerSentEventsTransport(this);
                NextProtocolToTry = SupportedProtocols.HTTP;
            }
            State = ConnectionStates.Connecting;
            TransportConnectionStartedAt = DateTime.UtcNow;
            Transport.Connect();
        }
Beispiel #7
0
        /// <summary>
        /// Connects this channel to the remote address and port.
        /// </summary>
        /// <param name="serverAddress">The server address to connect to.</param>
        /// <param name="port">The server port to connect to.</param>
        /// <returns>A Connected message providing information about the remote server.</returns>
        public void Connect(string serverAddress, int port)
        {
            Transport.Address = serverAddress;
            Transport.Port    = port;
            Transport.Connect();

            StartReceiveThread();
        }
Beispiel #8
0
        public void Connect(string serverAddress, int port)
        {
            Transport.Address = serverAddress;
            Transport.Port    = port;
            Transport.Connect();

            StartMessagePump();
        }
Beispiel #9
0
        public void Connect()
        {
            if (Transport == null)
            {
                return;
            }

            Transport.Connect();
        }
Beispiel #10
0
        /// <summary>
        /// Protocol negotiation finished successfully.
        /// </summary>
        private void OnNegotiationDataReceived(NegotiationData data)
        {
            // Find out what supported protocol the server speak
            int protocolIdx = -1;

            for (int i = 0; i < ClientProtocols.Length && protocolIdx == -1; ++i)
            {
                if (data.ProtocolVersion == ClientProtocols[i])
                {
                    protocolIdx = i;
                }
            }

            // No supported protocol found? Try using the latest one.
            if (protocolIdx == -1)
            {
                protocolIdx = (byte)ProtocolVersions.Protocol_2_2;
                HTTPManager.Logger.Warning("SignalR Connection", "Unknown protocol version: " + data.ProtocolVersion);
            }

            this.Protocol = (ProtocolVersions)protocolIdx;

#if !BESTHTTP_DISABLE_WEBSOCKET
            if (data.TryWebSockets)
            {
                Transport = new WebSocketTransport(this);

                #if !BESTHTTP_DISABLE_SERVERSENT_EVENTS
                NextProtocolToTry = SupportedProtocols.ServerSentEvents;
                #else
                NextProtocolToTry = SupportedProtocols.HTTP;
                #endif
            }
            else
#endif
            {
                #if !BESTHTTP_DISABLE_SERVERSENT_EVENTS
                Transport = new ServerSentEventsTransport(this);

                // Long-Poll
                NextProtocolToTry = SupportedProtocols.HTTP;
                #else
                Transport = new PollingTransport(this);

                NextProtocolToTry = SupportedProtocols.Unknown;
                #endif
            }

            this.State = ConnectionStates.Connecting;
            TransportConnectionStartedAt = DateTime.UtcNow;

            Transport.Connect();
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            // First, configure and start a local silo
            var siloConfig = ClusterConfiguration.LocalhostPrimarySilo();

            siloConfig.AddSimpleMessageStreamProvider(Common.Constants.InboundTransmissionStreamProvider);
            siloConfig.AddSimpleMessageStreamProvider(Common.Constants.OutboundTransmissionStreamProvider);
            var silo = new SiloHost("TestSilo", siloConfig);

            silo.Config.AddMemoryStorageProvider("PubSubStore");
            silo.InitializeOrleansSilo();
            silo.StartOrleansSilo();

            Console.WriteLine("Silo started.");

            // Then configure and connect a client.
            var clientConfig = ClientConfiguration.LocalhostSilo();

            clientConfig.AddSimpleMessageStreamProvider(Common.Constants.InboundTransmissionStreamProvider);
            clientConfig.AddSimpleMessageStreamProvider(Common.Constants.OutboundTransmissionStreamProvider);
            var client = new ClientBuilder().UseConfiguration(clientConfig).Build();

            client.Connect().Wait();

            Console.WriteLine("Client connected.");

            //
            // This is the place for your test code.
            //
            var transport = new Transport();

            var inboundSubscription = transport.Received
                                      .Subscribe(datagram => client.InboundTransmissionStream(datagram.IpAddress).OnNextAsync(datagram));

            var outboundSubscription = client.OutboundTransmissionStream()
                                       .SubscribeAsync((datagram, token) => transport.Send(datagram))
                                       .Result;

            var connection = transport.Connect();

            Console.WriteLine("\nPress Enter to terminate...");
            Console.ReadLine();
            Console.WriteLine("\nTerminating...");

            inboundSubscription.Dispose();
            outboundSubscription.UnsubscribeAsync().Wait();

            // Shut down
            client.Close();
            silo.ShutdownOrleansSilo();
        }
Beispiel #12
0
        /// <summary>
        /// Connects this channel to the remote address and port.
        /// </summary>
        /// <param name="serverAddress">The server address to connect to.</param>
        /// <param name="port">The server port to connect to.</param>
        /// <returns>A Connected message providing information about the remote server.</returns>
        public void Connect(string serverAddress, int port)
        {
            lock (sendLock)
            {
                // reset this so that a reused channel will wait for message responses
                sendResponded.Reset();
                sendResponse = null;

                Transport.Address = serverAddress;
                Transport.Port    = port;
                Transport.Connect();

                StartReceiveThread();
            }
        }
Beispiel #13
0
 private void joinNetworkButton_Click(object sender, EventArgs e) {
     if (!this.isConnect) {
         if (settings.IsValid()) {
             transport = new Transport(this);
             transport.Connect(settings.IncomingPortName, settings.OutgoingPortName);
             transport.InitGettingListClients();
             this.isConnect = true;
             ((Button)sender).Text = "Отключиться";
         } else {
             MessageBox.Show("Настройки неверны");
         }
     } else {
         connectionStatusNetwork.Text = "Не в сети";
         messageFormButton.Enabled = false;
         this.isConnect = false;
         ((Button)sender).Text = "Подключиться";
         transport.Disconnect();
     }
 }
        public bool Connect()
        {
            try
            {
                bool connect = Transport.Connect(Host, Port);

                if (connect && OnConnect != null)
                {
                    OnConnect(this);
                }

                return(connect);
            }
            catch (Exception e)
            {
                OnError(this, e);
                return(false);
            }
        }
Beispiel #15
0
 /// <summary>
 /// Connect to another peer running Adaptive
 /// </summary>
 /// <returns>The peer.</returns>
 /// <param name="hostName">Host name.</param>
 /// <param name="port">Port.</param>
 public Peer AddPeer(string hostName, int port)
 {
     Transport.Connect(hostName, port);
     return(null);
 }
Beispiel #16
0
 public bool Connect(string ip, int port)
 {
     return(_transport.Connect(ip, port));
 }