def connect(address=DEFAULT_ADDRESS, rpc_port=DEFAULT_RPC_PORT, stream_port=DEFAULT_STREAM_PORT, name=None): """ Connect to a kRPC server on the specified IP address and port numbers, and optionally give the kRPC server the supplied name to identify the client (up to 32 bytes of UTF-8 encoded text) """ assert rpc_port != stream_port # Connect to RPC server rpc_connection = Connection(address, rpc_port) rpc_connection.send(_Encoder.RPC_HELLO_MESSAGE) rpc_connection.send(_Encoder.client_name(name)) client_identifier = rpc_connection.receive(_Decoder.GUID_LENGTH) # Connect to Stream server stream_connection = Connection(address, stream_port) stream_connection.send(_Encoder.STREAM_HELLO_MESSAGE) stream_connection.send(client_identifier) ok_message = stream_connection.receive(_Decoder.OK_LENGTH) assert ok_message == _Decoder.OK_MESSAGE return Client(rpc_connection, stream_connection)
def connect(name=None, address=DEFAULT_ADDRESS, rpc_port=DEFAULT_RPC_PORT, stream_port=DEFAULT_STREAM_PORT): # type: (str, str, int, int) -> Client """ Connect to a kRPC server on the specified IP address and port numbers. If stream_port is None, does not connect to the stream server. Optionally give the kRPC server the supplied name to identify the client. """ # Connect to RPC server rpc_connection = Connection(address, rpc_port) rpc_connection.connect() request = ConnectionRequest() request.type = ConnectionRequest.RPC if name is not None: request.client_name = name rpc_connection.send_message(request) response = rpc_connection.receive_message(ConnectionResponse) if response.status != ConnectionResponse.OK: raise ConnectionError(response.message) client_identifier = response.client_identifier # Connect to Stream server if stream_port is not None: stream_connection = Connection(address, stream_port) stream_connection.connect() request = ConnectionRequest() request.type = ConnectionRequest.STREAM request.client_identifier = client_identifier stream_connection.send_message(request) response = stream_connection.receive_message(ConnectionResponse) if response.status != ConnectionResponse.OK: raise ConnectionError(response.message) else: stream_connection = None return Client(rpc_connection, stream_connection)
def connect(self): conn = Connection('localhost', port) conn.connect() return conn
def connect(): conn = Connection('localhost', server_thread.port) conn.connect() return conn
def connect(address=DEFAULT_ADDRESS, rpc_port=DEFAULT_RPC_PORT, stream_port=DEFAULT_STREAM_PORT, name=None): """ Connect to a kRPC server on the specified IP address and port numbers. If stream_port is None, does not connect to the stream server. Optionally give the kRPC server the supplied name to identify the client (up to 32 bytes of UTF-8 encoded text). """ assert rpc_port != stream_port # Connect to RPC server rpc_connection = Connection(address, rpc_port) rpc_connection.connect(retries=10, timeout=0.1) rpc_connection.send(Encoder.RPC_HELLO_MESSAGE) rpc_connection.send(Encoder.client_name(name)) client_identifier = rpc_connection.receive(Decoder.GUID_LENGTH) # Connect to Stream server if stream_port is not None: stream_connection = Connection(address, stream_port) stream_connection.connect(retries=10, timeout=0.1) stream_connection.send(Encoder.STREAM_HELLO_MESSAGE) stream_connection.send(client_identifier) ok_message = stream_connection.receive(Decoder.OK_LENGTH) assert ok_message == Decoder.OK_MESSAGE else: stream_connection = None return Client(rpc_connection, stream_connection)
def connect(name=None, address=DEFAULT_ADDRESS, rpc_port=DEFAULT_RPC_PORT, stream_port=DEFAULT_STREAM_PORT): """ Connect to a kRPC server on the specified IP address and port numbers. If stream_port is None, does not connect to the stream server. Optionally give the kRPC server the supplied name to identify the client. """ # Connect to RPC server rpc_connection = Connection(address, rpc_port) rpc_connection.connect() request = ConnectionRequest() request.type = ConnectionRequest.RPC if name is not None: request.client_name = name rpc_connection.send_message(request) response = rpc_connection.receive_message(ConnectionResponse) if response.status != ConnectionResponse.OK: raise ConnectionError(response.message) client_identifier = response.client_identifier # Connect to Stream server if stream_port is not None: stream_connection = Connection(address, stream_port) stream_connection.connect() request = ConnectionRequest() request.type = ConnectionRequest.STREAM request.client_identifier = client_identifier stream_connection.send_message(request) response = stream_connection.receive_message(ConnectionResponse) if response.status != ConnectionResponse.OK: raise ConnectionError(response.message) else: stream_connection = None return Client(rpc_connection, stream_connection)