Пример #1
0
        public RpcUdpClient(
            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.Udp, ipAddress, program, version, portMapperClientSettings);
            }

            var remoteIpEndPoint = new IPEndPoint(ipAddress, port);

            this.client         = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            this.ReceiveTimeout = clientSettings?.ReceiveTimeout ?? Utilities.DefaultClientReceiveTimeout;
            this.SendTimeout    = clientSettings?.SendTimeout ?? Utilities.DefaultClientSendTimeout;
            var reader = new UdpReader(this.client);
            var writer = new UdpWriter(this.client);

            this.call = new RpcCall(program, remoteIpEndPoint, reader, writer, null, clientSettings?.Logger);
        }
Пример #2
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);
        }