def test_client_server(self): client = None server = None try: try: server = Mserver.TCPServer(opts={'open': True}) except: print("Skipping because of server open failure") return print("Server port is %s" % server.PORT) try: client = Mclient.TCPClient(opts={'open': True, 'PORT': server.PORT}) except IOError: print("Skipping because of client open failure") return for line in ['one', 'two', 'three']: server.writeline(line) self.assertEqual(line, client.read_msg().rstrip('\n')) pass for line in ['four', 'five', 'six']: client.writeline(line) self.assertEqual(line, server.read_msg().rstrip('\n')) pass finally: if client: client.close() if server: server.close() return
def __init__(self, inp=None, out=None, inout=None, user_opts={}, connection_opts={}): opts = DEFAULT_INIT_CONNECTION_OPTS.copy() opts.update(connection_opts) Muser.UserInterface.__init__(self, inp, out, user_opts) self.inout = None # initialize in case assignment below fails if inout: self.inout = inout else: self.server_type = opts['IO'] if 'FIFO' == self.server_type: self.inout = Mfifoclient.FIFOClient(opts=opts) elif 'TCP' == self.server_type: self.inout = Mtcpclient.TCPClient(opts=opts) else: self.errmsg("Expecting server type TCP or FIFO. Got: %s." % self.server_type) return pass return
def __init__(self, inp=None, out=None, inout=None, user_opts=None, connection_opts=None): get_connection_option = lambda key: \ Mmisc.option_set(connection_opts, key, self.DEFAULT_INIT_CONNECTION_OPTS) Muser.UserInterface.__init__(self, inp, out, user_opts) self.inout = None # initialize in case assignment below fails if inout: self.inout = inout else: self.server_type = get_connection_option('IO') if 'FIFO' == self.server_type: # print(connection_opts) self.inout = Mfifoclient.FIFOClient(opts=connection_opts) elif 'TCP' == self.server_type: self.inout = Mtcpclient.TCPClient(opts=connection_opts) else: self.errmsg("Expecting server type TCP or FIFO. Got: %s." % self.server_type) return pass return
def test_client_server(self): try: server = Mserver.TCPServer(opts={'open': True}) except: print("Skipping because of server open failure") return try: client = Mclient.TCPClient(opts={'open': True}) for line in ['one', 'two', 'three']: server.writeline(line) self.assertEqual(line, client.read_msg().rstrip('\n')) pass for line in ['four', 'five', 'six']: client.writeline(line) self.assertEqual(line, server.read_msg().rstrip('\n')) pass except: print("Skipping because of client open failure") pass client.close() server.close() return