Esempio n. 1
0
        /// <summary>
        /// Connect to a kRPC server on the specified IP address and port numbers. If
        /// streamPort is 0, does not connect to the stream server.
        /// Passes an optional name to the server to identify the client (up to 32 bytes of UTF-8 encoded text).
        /// </summary>
        public Connection(string name = "", IPAddress address = null, int rpcPort = 50000, int streamPort = 50001)
        {
            if (address == null)
            {
                address = IPAddress.Loopback;
            }

            rpcClient = new TcpClient();
            rpcClient.Connect(address, rpcPort);
            var rpcStream = rpcClient.GetStream();

            rpcStream.Write(Encoder.rpcHelloMessage, 0, Encoder.rpcHelloMessage.Length);
            var clientName = Encoder.EncodeClientName(name);

            rpcStream.Write(clientName, 0, clientName.Length);
            var clientIdentifier = new byte[Encoder.clientIdentifierLength];

            rpcStream.Read(clientIdentifier, 0, Encoder.clientIdentifierLength);

            if (streamPort == 0)
            {
                StreamManager = null;
            }
            else
            {
                StreamManager = new StreamManager(this, address, streamPort, clientIdentifier);
            }
        }
Esempio n. 2
0
        public Connection(string name = "", IPAddress address = null, int rpcPort = 50000, int streamPort = 50001)
        {
            if (address == null)
            {
                address = IPAddress.Loopback;
            }

            rpcClient = new TcpClient();
            rpcClient.Connect(address, rpcPort);
            rpcStream = rpcClient.GetStream();
            rpcStream.Write(Encoder.RPCHelloMessage, 0, Encoder.RPCHelloMessage.Length);
            var clientName = Encoder.EncodeClientName(name);

            rpcStream.Write(clientName, 0, clientName.Length);
            var clientIdentifier = new byte[Encoder.ClientIdentifierLength];

            rpcStream.Read(clientIdentifier, 0, Encoder.ClientIdentifierLength);
            codedRpcStream = new CodedOutputStream(rpcStream, true);

            if (streamPort != 0)
            {
                streamClient = new TcpClient();
                streamClient.Connect(address, streamPort);
                var streamStream = streamClient.GetStream();
                streamStream.Write(Encoder.StreamHelloMessage, 0, Encoder.StreamHelloMessage.Length);
                streamStream.Write(clientIdentifier, 0, clientIdentifier.Length);
                var recvOkMessage = new byte [Encoder.OkMessage.Length];
                streamStream.Read(recvOkMessage, 0, Encoder.OkMessage.Length);
                if (!recvOkMessage.SequenceEqual(Encoder.OkMessage))
                {
                    throw new InvalidOperationException("Did not receive OK message from server");
                }
                StreamManager = new StreamManager(this, streamClient);
            }
        }
Esempio n. 3
0
 internal UpdateThread(StreamManager manager, IPAddress address, int port, byte[] clientIdentifier)
 {
     this.manager          = manager;
     this.address          = address;
     this.port             = port;
     this.clientIdentifier = clientIdentifier;
 }
Esempio n. 4
0
        public Connection(string name = "", IPAddress address = null, int rpcPort = 50000, int streamPort = 50001)
        {
            if (address == null)
            {
                address = IPAddress.Loopback;
            }

            rpcClient = new TcpClient();
            rpcClient.Connect(address, rpcPort);
            rpcStream      = rpcClient.GetStream();
            codedRpcStream = new CodedOutputStream(rpcStream, true);
            var request = new ConnectionRequest();

            request.Type       = Type.Rpc;
            request.ClientName = name;
            codedRpcStream.WriteLength(request.CalculateSize());
            request.WriteTo(codedRpcStream);
            codedRpcStream.Flush();
            int size     = ReadMessageData(rpcStream, ref responseBuffer);
            var response = ConnectionResponse.Parser.ParseFrom(new CodedInputStream(responseBuffer, 0, size));

            if (response.Status != ConnectionResponse.Types.Status.Ok)
            {
                throw new ConnectionException(response.Message);
            }

            if (streamPort != 0)
            {
                streamClient = new TcpClient();
                streamClient.Connect(address, streamPort);
                var streamStream = streamClient.GetStream();
                request                  = new ConnectionRequest();
                request.Type             = Type.Stream;
                request.ClientIdentifier = response.ClientIdentifier;
                var codedStreamStream = new CodedOutputStream(streamStream, true);
                codedStreamStream.WriteLength(request.CalculateSize());
                request.WriteTo(codedStreamStream);
                codedStreamStream.Flush();
                size     = ReadMessageData(streamStream, ref responseBuffer);
                response = ConnectionResponse.Parser.ParseFrom(new CodedInputStream(responseBuffer, 0, size));
                if (response.Status != ConnectionResponse.Types.Status.Ok)
                {
                    throw new ConnectionException(response.Message);
                }
                StreamManager = new StreamManager(this, streamClient);
            }

            Services.KRPC.Service.AddExceptionTypes(this);
        }
Esempio n. 5
0
 internal UpdateThread(StreamManager manager, IPAddress address, int port, byte[] clientIdentifier)
 {
     this.manager = manager;
     this.address = address;
     this.port = port;
     this.clientIdentifier = clientIdentifier;
 }
Esempio n. 6
0
 public UpdateThread(StreamManager streamManager, TcpClient streamClient)
 {
     manager = streamManager;
     stream  = streamClient.GetStream();
 }
Esempio n. 7
0
 internal Stream(Connection connection, Request request)
 {
     streamManager = connection.StreamManager;
     Id            = streamManager.AddStream(request, typeof(ReturnType));
 }
Esempio n. 8
0
 public UpdateThread (StreamManager streamManager, TcpClient streamClient)
 {
     manager = streamManager;
     stream = streamClient.GetStream ();
 }