예제 #1
0
        public RpcTcpClient(
            IPAddress ipAddress,
            int program,
            int version,
            ClientSettings clientSettings = default)
        {
            int port = clientSettings?.Port ?? 0;

            if (port == 0)
            {
                var portMapperClientSettings = new PortMapperClientSettings
                {
                    Port = clientSettings?.PortMapperPort ?? PortMapperConstants.PortMapperPort
                };
                port = PortMapperUtilities.GetPort(Protocol.Tcp, ipAddress, program, version, portMapperClientSettings);
            }

            this.remoteIpEndPoint = new IPEndPoint(ipAddress, port);
            this.client           = new Socket(SocketType.Stream, ProtocolType.Tcp);
            this.ReceiveTimeout   = clientSettings?.ReceiveTimeout ?? Utilities.DefaultClientReceiveTimeout;
            this.SendTimeout      = clientSettings?.SendTimeout ?? Utilities.DefaultClientSendTimeout;
            this.EstablishConnection();
            this.tcpReader = new TcpReader(this.client, clientSettings?.Logger);
            this.tcpWriter = new TcpWriter(this.client, clientSettings?.Logger);
            this.call      = new RpcCall(
                program,
                this.remoteIpEndPoint,
                this.tcpReader,
                this.tcpWriter,
                this.ReestablishConnection,
                clientSettings?.Logger);
        }
예제 #2
0
        public RpcTcpConnection(
            Socket tcpClient,
            int program,
            int[] versions,
            Action <ReceivedRpcCall> receivedCallDispatcher,
            ILogger logger = default)
        {
            this.tcpClient        = tcpClient;
            this.remoteIpEndPoint = (IPEndPoint)tcpClient.RemoteEndPoint;
            this.caller           = new Caller(this.remoteIpEndPoint, Protocol.Tcp);
            this.reader           = new TcpReader(tcpClient, logger);
            this.writer           = new TcpWriter(tcpClient, logger);
            this.logger           = logger;

            this.receivedCall = new ReceivedRpcCall(
                program,
                versions,
                this.reader,
                this.writer,
                receivedCallDispatcher);

            this.receivingThread = new Thread(this.Receiving)
            {
                IsBackground = true, Name = $"RpcNet TCP Connection {this.remoteIpEndPoint}"
            };
            this.receivingThread.Start();
        }