A UDP Uppercase Server
import SocketServer
import netstring
import sys
class MyRequestHandler(SocketServer.BaseRequestHandler):
def handle(self):
global Done
request, socket = self.request
rq = netstring.decode(request)
print "From:", self.client_address, ":", rq
sys.stdout.flush()
result = netstring.encode(rq.upper())
if result == "END":
Done = 1
return
socket.sendto(result, self.client_address)
myServer = SocketServer.UDPServer(('', 8081),MyRequestHandler)
Done = None
while not Done:
myServer.handle_request()
Related examples in the same category