Example #1
0
        /// <summary>
        /// Attempts the connection with retry
        /// </summary>
        /// <param name='retries'>
        /// Retries.
        /// </param>
        /// <param name='timeout'>
        /// Timeout in seconds
        /// </param>
        private void AttemptConnection(int retries = 10, int timeout = 5)
        {
            Exception error = null;

            for (int i = 0; i <= retries; i++)
            {
                if (i > 0)
                {
                    Console.Error.WriteLine("clr: failed to connect to clr server, will retry in " + timeout + " secs, url: " + Url);
                    Thread.Sleep(timeout * 1000);
                }

                try
                {
                    _client = new TcpClient();
                    _client.Connect(Url.Host, Url.Port);
                    _client.NoDelay = true;
                    _stream         = new BufferedDuplexStream(_client.GetStream());
                    _cin            = EndianStreams.ReaderFor(_stream, EndianStreams.Endian.Little);
                    _cout           = EndianStreams.WriterFor(_stream, EndianStreams.Endian.Little);
                    return;
                }
                catch (Exception e)
                {
                    _client = null;
                    error   = e;
                }
            }

            throw error;
        }
Example #2
0
        /// <summary>
        /// Handle incoming clients
        /// </summary>
        private void Service()
        {
            while (true)
            {
                var client_socket = _server_socket.Accept();

                _log.Info("execution: received new client from: " + client_socket.RemoteEndPoint);
                client_socket.NoDelay = true;
                var stream = new BufferedDuplexStream(new NetworkStream(client_socket));
                var client = new CLRBridgeServerClient(stream, client_socket.RemoteEndPoint);

                client.Start();
            }
        }