Commits

damoxc committed 0038358

make py3 compatible

  • Participants
  • Parent commits 95c9567

Comments (0)

Files changed (1)

File examples/echoserver.py

 
 # this handler will be run for each incoming connection in a dedicated greenlet
 def echo(socket, address):
-    print 'New connection from %s:%s' % address
+    print ('New connection from %s:%s' % address)
     # using a makefile because we want to use readline()
     fileobj = socket.makefile()
     fileobj.write('Welcome to the echo server! Type quit to exit.\r\n')
     while True:
         line = fileobj.readline()
         if not line:
-            print "client disconnected"
+            print ("client disconnected")
             break
         if line.strip().lower() == 'quit':
-            print "client quit"
+            print ("client quit")
             break
         fileobj.write(line)
         fileobj.flush()
-        print "echoed", repr(line)
+        print ("echoed %r" % line)
+
+    socket.close()
+    fileobj.close()
 
 
 if __name__ == '__main__':
     server = StreamServer(('0.0.0.0', 6000), echo)
     # to start the server asynchronously, use its start() method;
     # we use blocking serve_forever() here because we have no other jobs
-    print 'Starting echo server on port 6000'
+    print ('Starting echo server on port 6000')
     server.serve_forever()