예제 #1
0
        /// <summary>
        /// Constructs an instance and attempts to connect it to given host.
        /// </summary>
        /// <param name="host">The DNS name of the remote RPC host</param>
        /// <param name="port">The port number of the remote RPC host</param>
        /// <exception cref="ArgumentNullException"><paramref name="host"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not between System.Net.IPEndPoint.MinPort and System.Net.IPEndPoint.MaxPort.</exception>
        /// <exception cref="System.Net.Sockets.SocketException">An error occurred when accessing the socket.</exception>
        public TcpRpcClient(string host, int port)
        {
            _rpcEngine = new RpcEngine();
            _client    = new TcpClient();

            WhenConnected = Connect(host, port);
        }
예제 #2
0
        /// <summary>
        /// Constructs an instance and attempts to connect it to given host.
        /// </summary>
        /// <param name="host">The DNS name of the remote RPC host</param>
        /// <param name="port">The port number of the remote RPC host</param>
        /// <exception cref="ArgumentNullException"><paramref name="host"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not between System.Net.IPEndPoint.MinPort and System.Net.IPEndPoint.MaxPort.</exception>
        /// <exception cref="System.Net.Sockets.SocketException">An error occurred when accessing the socket.</exception>
        public TcpRpcClient(string host, int port)
        {
            _rpcEngine = new RpcEngine();
            _client    = new TcpClient();
            _client.ExclusiveAddressUse = false;

            WhenConnected = Connect(host, port);
        }
예제 #3
0
 public EnginePair()
 {
     Engine1   = new RpcEngine();
     Engine2   = new RpcEngine();
     _channel1 = new EngineChannel();
     Endpoint1 = Engine1.AddEndpoint(_channel1);
     _channel2 = new EngineChannel();
     Endpoint2 = Engine2.AddEndpoint(_channel2);
     _channel1.OtherEndpoint = Endpoint2;
     _channel2.OtherEndpoint = Endpoint1;
 }
예제 #4
0
 public EnginePair(DecisionTree decisionTree)
 {
     _decisionTree           = decisionTree;
     Engine1                 = new RpcEngine();
     Engine2                 = new RpcEngine();
     _channel1               = new EngineChannel(decisionTree.MakeDecision);
     Endpoint1               = Engine1.AddEndpoint(_channel1);
     _channel2               = new EngineChannel(() => false);
     Endpoint2               = Engine2.AddEndpoint(_channel2);
     _channel1.OtherEndpoint = Endpoint2;
     _channel2.OtherEndpoint = Endpoint1;
 }
        /// <summary>
        /// Constructs an instance.
        /// </summary>
        /// <param name="localAddr">An System.Net.IPAddress that represents the local IP address.</param>
        /// <param name="port">The port on which to listen for incoming connection attempts.</param>
        /// <exception cref="ArgumentNullException"><paramref name="localAddr"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not between System.Net.IPEndPoint.MinPort and System.Net.IPEndPoint.MaxPort.</exception>
        public TcpRpcServer(IPAddress localAddr, int port)
        {
            _rpcEngine = new RpcEngine();
            _listener  = new TcpListener(localAddr, port);
            _listener.Start();

            _acceptorThread = new Thread(() =>
            {
                AcceptClients();
            });

            _acceptorThread.Start();
        }
예제 #6
0
 // return the RpcEngine configured to handle a protocol
 internal static RpcEngine GetProtocolEngine(Type protocol, Configuration conf)
 {
     lock (typeof(RPC))
     {
         RpcEngine engine = ProtocolEngines[protocol];
         if (engine == null)
         {
             Type impl = conf.GetClass(EngineProp + "." + protocol.FullName, typeof(WritableRpcEngine
                                                                                    ));
             engine = (RpcEngine)ReflectionUtils.NewInstance(impl, conf);
             ProtocolEngines[protocol] = engine;
         }
         return(engine);
     }
 }
예제 #7
0
        /// <summary>
        /// Constructs an instance.
        /// </summary>
        /// <param name="localAddr">An System.Net.IPAddress that represents the local IP address.</param>
        /// <param name="port">The port on which to listen for incoming connection attempts.</param>
        /// <exception cref="ArgumentNullException"><paramref name="localAddr"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not between System.Net.IPEndPoint.MinPort and System.Net.IPEndPoint.MaxPort.</exception>
        public TcpRpcServer(IPAddress localAddr, int port)
        {
            _rpcEngine = new RpcEngine();
            _listener  = new TcpListener(localAddr, port);
            _listener.ExclusiveAddressUse = false;

            for (int retry = 0; retry < 5; retry++)
            {
                try
                {
                    _listener.Start();
                    break;
                }
                catch (SocketException socketException)
                {
                    Logger.LogWarning($"Failed to listen on port {port}, attempt {retry}: {socketException}");
                    Thread.Sleep(10);
                }
            }

            _acceptorThread = new Thread(AcceptClients);

            _acceptorThread.Start();
        }
예제 #8
0
 /// <summary>
 /// Constructs an instance but does not yet attempt to connect.
 /// </summary>
 public TcpRpcClient()
 {
     _rpcEngine = new RpcEngine();
     _client    = new TcpClient();
     _client.ExclusiveAddressUse = false;
 }
예제 #9
0
 /// <summary>
 /// Constructs an instance.
 /// </summary>
 public TcpRpcServer()
 {
     _rpcEngine = new RpcEngine();
 }