python - UDP Socketserver - send data through same socket (impossible?) -


i have computer may behind several firewalls, have private ip... pretty not reachable outside world.

that computer periodically sends udp data remote server (accessible everywhere). remote server in different network udp sender/client (or in different country matter).

at point, have send package acknowledging received data "unreachable" computer, meaning: client started communication , have socket.

i afraid of answer, because of read of udp protocol being send-->disconnect-->forget package, here goes question. there way of sending data using existing udp socket?

as server, i'm using simple socketserver class:

class myudphandler(socketserver.baserequesthandler):      def handle(self):         message_type = message_utils.extract_type(self.request[0])         message_cls = message_factory.get_class_by_message_type(message_type)         message = message_cls(                               data=self.request[0],                               came_from=self.client_address)         print "got %s" % message         message.process()         self.request[1].send("test")   if __name__ == "__main__":     server_host = settings.server_host\                         if hasattr(settings, "server_host") else ""     server_port = int(settings.server_port)     server = socketserver.udpserver(                                     (server_host, server_port),                                     myudphandler)     server.serve_forever() 

the line self.request[1].send("test") failing error: [errno 89] destination address required , more read it, more think won't able send data client, @ least not simple "send" solution.

i can not change client. there way send udp data reusing socket? maybe there's "savior" class out there don't know about? hint appreciated.

thank in advance.

you must use .sendto(), not .send(), this:

self.request[1].sendto(   "test",   self.client_address)  

reference: http://docs.python.org/2/library/socketserver.html#socketserver-udpserver-example


extras:

the smallest responsive udp socket server can create this:

import socketserver class myudphandler(socketserver.baserequesthandler):     def handle(self):         self.request[1].sendto( "test\n", self.client_address) socketserver.udpserver( ("", 5432), myudphandler).serve_forever() 

it can tested linux command line thusly:

$ nc -u 127.1 5432 


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -