def test_socket_creation(): sock = TCP("example.com", 34567) assert sock.host == "example.com" assert sock.port == 34567 assert sock.auto_reconnect is True assert not sock.connected() assert sock.connection_counter == 0
def test_socket_creation(): sock = TCP('example.com', 34567) assert sock.host == 'example.com' assert sock.port == 34567 assert sock.auto_reconnect == True assert not sock.connected assert sock.connection_counter == 0
def test_write_readline_fail(unused_tcp_port): sock = TCP("0", unused_tcp_port) assert not sock.connected() assert sock.connection_counter == 0 with pytest.raises(ConnectionRefusedError): sock.write_readline(IDN_REQ) assert not sock.connected() assert sock.connection_counter == 0
def test_open_fail(unused_tcp_port): sock = TCP("0", unused_tcp_port) assert not sock.connected() assert sock.connection_counter == 0 with pytest.raises(ConnectionRefusedError): sock.open() assert not sock.connected() assert sock.connection_counter == 0
def __init__(self, host, port=SCPI_CONTROL_PORT, zmq_port=ZMQ_STREAMING_PORT): self.host = host self.port = port self._sock = TCP(host, port) self._zmq_receiver = ZmqStreamReceiver(host, zmq_port) # TODO: Remove when sardana allows to use the configuration file logging.getLogger('sockio').setLevel(logging.INFO) self.log = logging.getLogger('em2.Em2({0}:{1})'.format(host, port)) self.log.setLevel(logging.INFO) self.channels = [ Channel(self, i) for i in range(CHANNEL_MIN, CHANNEL_MAX + 1) ] self._software_version = None self._read_index_bug = None self._long_acquisition_scaling_bug = None self._zmq_streaming_supported = None
def connect_to_SOS(): """Establish a connection with the Science on a Sphere application""" while True: # Sleep for 5 seconds so that we don't spam the connection print("Connecting in 5 seconds...") time.sleep(5) try: # Send Science on a Sphere command to begin communication socket = TCP(config.defaults_dict["sos_ip_address"], 2468) socket.write_readline(b'enable\n') print("Connected!") break except ConnectionRefusedError as e: print("Error: Connection with Science on a Sphere failed to initialize. Make sure you have specificed sos_ip_address in defaults.ini, both computers are on the same network (or are the same machine), and port 2468 is accessible.") if DEBUG: print(e) return socket
def test_callbacks(sio_server): host, port = sio_server.sockets[0].getsockname() state = dict(made=0, lost=0, eof=0) def made(): state["made"] += 1 def lost(exc): state["lost"] += 1 def eof(): state["eof"] += 1 sio_tcp = TCP( host, port, on_connection_made=made, on_connection_lost=lost, on_eof_received=eof, ) assert not sio_tcp.connected() assert sio_tcp.connection_counter == 0 assert state["made"] == 0 assert state["lost"] == 0 assert state["eof"] == 0 sio_tcp.open() assert sio_tcp.connected() assert sio_tcp.connection_counter == 1 assert state["made"] == 1 assert state["lost"] == 0 assert state["eof"] == 0 with pytest.raises(ConnectionError): sio_tcp.open() assert sio_tcp.connected() assert sio_tcp.connection_counter == 1 assert state["made"] == 1 assert state["lost"] == 0 assert state["eof"] == 0 sio_tcp.close() assert not sio_tcp.connected() assert sio_tcp.connection_counter == 1 assert state["made"] == 1 assert state["lost"] == 1 assert state["eof"] == 0 sio_tcp.open() assert sio_tcp.connected() assert sio_tcp.connection_counter == 2 assert state["made"] == 2 assert state["lost"] == 1 assert state["eof"] == 0 sio_tcp.close() assert not sio_tcp.connected() assert sio_tcp.connection_counter == 2 assert state["made"] == 2 assert state["lost"] == 2 assert state["eof"] == 0 sio_tcp.close() assert not sio_tcp.connected() assert sio_tcp.connection_counter == 2 assert state["made"] == 2 assert state["lost"] == 2 assert state["eof"] == 0