Note that there are some explanatory texts on larger screens.

plurals
  1. POPython server for hosting sockets and reading data
    text
    copied!<p>I'm trying to create a python server that will serve calls from outer source through sockets. So I've skimmed through the docs and copied this code, I can connect but no sent data is shown. What am I doing wrong ?</p> <pre><code>import SocketServer class MyUDPHandler(SocketServer.BaseRequestHandler): def handle(self): self.data = self.rfile.readline().strip() print "%s wrote:" % self.client_address[0] print self.data self.wfile.write(self.data.upper()) if __name__ == "__main__": HOST, PORT = "localhost", 80 try: server = SocketServer.UDPServer((HOST, PORT), MyUDPHandler) print("working") server.serve_forever() serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) serversocket.bind((socket.gethostname(), 80)) serversocket.listen(5) except: print("not working") while True: (clientsocket, address) = serversocket.accept() ct = client_thread(clientsocket) ct.run() class mysocket: def __init__(self, sock=None): if sock is None: self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) else: self.sock = sock def connect(self, host, port): self.sock.connect((host, port)) def mysend(self, msg): totalsent = 0 while totalsent &lt; MSGLEN: sent = self.sock.send(msg[totalsent:]) if sent == 0: raise RuntimeError("socket connection broken") totalsent = totalsent + sent def myreceive(self): msg = '' while len(msg) &lt; MSGLEN: chunk = self.sock.recv(MSGLEN-len(msg)) if chunk == '': raise RuntimeError("socket connection broken") msg = msg + chunk return msg </code></pre> <p>And moreover, if this code is proper - how to use it ? I'm just setting the server now with python server.py which creates an instance of MyUdpHandler but what next ? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload