Пример #1
0
        public bool Connect(string serverhost, int port)
        {
            client.GetMessage += OnGetMessage;
            bool b = client.Connect(serverhost, port);

            return(b);
        }
Пример #2
0
        public Client(IPEndPoint serverAddress, IController controller, INetClient client)
        {
            _controller = controller;

            _client = client;
            _client.Start();

            _client.Connect(serverAddress);

            Scene = new Scene();
            Scene.Gravity = new Vector2();
        }
Пример #3
0
 /// <summary>
 /// Connects to the media server.
 /// </summary>
 /// <param name="roomId">The room on the media server</param>
 /// <param name="callback">An optional callback to be called when connection is finished.</param>
 /// <remarks>
 /// The connection process is complicated, due to the fact that we have to first connect to the control port (4521),
 /// and then if that is successful, we then connect to the data port (4522).  And of course, both connection attempts are
 /// asynchronous. The result is that the logic in a successful connection attempt flows like this:
 ///   Connect() -> controlClient.Connect() =>
 ///   HandleControlConnect() -> RegisterClientOnServer() -> controlClient.Send() =>
 ///   HandleControlData() -> rtpClient.Connect() =>
 ///   HandleRtpConnect() -> rtpClient.Send() =>
 ///   HandleRtpData() -> FinalizeConnection() -> connectionCallback()
 /// An error anywhere in that flow will result in control being transferred to FinalizeConnection().
 /// </remarks>
 public virtual void Connect(string roomId, Action <Exception> callback = null)
 {
     if (!IsConnecting)
     {
         _roomId             = roomId;
         _connectionTimer    = new Timer(ConnectionTimerCallback, null, TimeSpan.FromSeconds(60), TimeSpan.FromMilliseconds(-1));
         _connectionCallback = callback;
         _controlClient.Connect(HandleControlConnect, HandleControlData);                 // -> HandleControlConnect
     }
     else
     {
         FinalizeConnection(null);
     }
 }
Пример #4
0
        public bool Connect()
        {
            int port;

            // TryParse incase the user entered non-float string
            if (int.TryParse(ServerPort, out port))
            {
                try
                {
                    netClient.Connect(port, ServerIP);
                    // won't get here if an exception was thrown during connect
                    return(true);
                }
                catch (Exception ex) { Trace.WriteLine(ex); }
            }
            return(false);
        }
Пример #5
0
        /// <summary>
        /// Callback method called after sending registration data to the media server over control port (typically 4521).
        /// </summary>
        /// <param name="data">The byte array containing the data sent by the media server</param>
        /// <param name="offset">The offset into the byte array where the actual data starts</param>
        /// <param name="length">The length of the data sent by the media server</param>
        protected virtual void HandleControlData(byte[] data, int offset, int length)
        {
            if (_disposed)
            {
                return;
            }
            try
            {
                if (_expectingControlData)
                {
                    _expectingControlData = false;
                    string message = Encoding.UTF8.GetString(data, offset, length);                     // .Split('\0')[0];
                    _commandSet.ParseResult(message);
                    if (CheckSuccess(_commandSet))
                    {
                        _rtpClient.Connect(HandleRtpConnect, HandleRtpData);                         // -> HandleRtpConnect
                    }
                    else
                    {
                        string errorMessage = MediaStrings.FailedToRegister;
#if DEBUG
                        errorMessage += Environment.NewLine + "Server = " + _rtpClient.Host + "; Port = " + _rtpClient.Port;
#endif
                        FinalizeConnection(new Exception(errorMessage));
                    }
                }
                else
                {
                    ClientLogger.Error("Unexpectedly received control data.");
                }
            }
            catch (Exception ex)
            {
                ClientLogger.ErrorException(ex, "Handle control data failed");
                FinalizeConnection(ex);
            }
        }