private void Connect()
        {
            var radioSync = new RadioDCSSyncServer(ClientRadioUpdated, ClientCoalitionUpdate, _clients, _guid);

            using (_tcpClient = new TcpClient())
            {
                _tcpClient.SendTimeout = 10;
                try
                {
                    _tcpClient.NoDelay = true;

                    _tcpClient.Connect(_serverEndpoint);

                    if (_tcpClient.Connected)
                    {
                        radioSync.Listen();

                        _tcpClient.NoDelay = true;

                        CallOnMain(true);
                        ClientSyncLoop();
                    }
                }
                catch (SocketException ex)
                {
                    Logger.Error(ex, "error connecting to server");
                }
            }

            radioSync.Stop();

            //disconnect callback
            CallOnMain(false);
        }
Example #2
0
        private void Connect()
        {
            if (_radioDCSSync != null)
            {
                _radioDCSSync.Stop();
                _radioDCSSync = null;
            }

            bool connectionError = false;

            _radioDCSSync = new RadioDCSSyncServer(ClientRadioUpdated, ClientCoalitionUpdate, _clients, _guid);
            using (_tcpClient = new TcpClient())
            {
                _tcpClient.SendTimeout = 10;
                try
                {
                    _tcpClient.NoDelay = true;

                    // Wait for 10 seconds before aborting connection attempt - no SRS server running/port opened in that case
                    _tcpClient.ConnectAsync(_serverEndpoint.Address, _serverEndpoint.Port).Wait(TimeSpan.FromSeconds(10));

                    if (_tcpClient.Connected)
                    {
                        _radioDCSSync.Listen();

                        _tcpClient.NoDelay = true;

                        CallOnMain(true);
                        ClientSyncLoop();
                    }
                    else
                    {
                        Logger.Error($"Failed to connect to server @ {_serverEndpoint.ToString()}");

                        // Signal disconnect including an error
                        connectionError = true;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "Could not connect to server");
                    connectionError = true;
                }
            }

            _radioDCSSync.Stop();

            //disconnect callback
            CallOnMain(false, connectionError);
        }