def test_TCPServer(self): from rospy.impl.tcpros_base import TCPServer def handler(sock, addr): pass s = None try: s = TCPServer(handler) self.assert_(s.port > 0) addr, port = s.get_full_addr() self.assert_(type(addr) == str) self.assertEquals(handler, s.inbound_handler) self.failIf(s.is_shutdown) finally: if s is not None: s.shutdown() self.assert_(s.is_shutdown)
def test_TCPServer(self): from rospy.impl.tcpros_base import TCPServer def handler(sock, addr): pass s = None try: s = TCPServer(handler) self.assert_(s.port > 0) addr, port = s.get_full_addr() self.assert_(type(addr) == str) self.assertEquals(handler, s.inbound_handler) self.failIf(s.is_shutdown) finally: if s is not None: s.shutdown() self.assert_(s.is_shutdown)
PORT = 2048 inputs = [] def inbound_handler(sock, addr): print "%s connected." % (str(addr)) t = TCPROSTransport(TestServerProtocol(), "testservice") t.set_socket(sock, "client") t.write_header() t.read_header() inputs.append(sock) if __name__ == '__main__': s = TCPServer(inbound_handler, PORT) s.start() while True: inputready,outputready,exceptready = select.select(inputs, [], [], 1) for s in inputready: # s is really just a python socket, but let's use # ROS to parse the message and write a response t = TCPROSTransport(TestServerProtocol(), "testservice") t.set_socket(s, "client") try: data = t.receive_once() # Echo all messages seq = 0 for msg in data: