Attachment 'miniserver.py'

Download

   1 #!/usr/bin/env python
   2 import socket
   3 import sys
   4 
   5 # Skuste: 
   6 # telnet 127.0.0.1 2222
   7 # ukoncite CTRL-] a potom quit
   8 
   9 # Vytvorime TCP socket
  10 s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  11 # Naviazeme ho na port 2222 pre vsetky lokalne adresy
  12 s.bind(('',2222))
  13 # Najviac 5 spojeni bude cakat vo fronte
  14 s.listen(5)
  15 try:
  16     while True:
  17         connected_socket,address=s.accept()
  18         print 'Connected by %s' % address
  19         while True:
  20             data=connected_socket.recv(1024)
  21             if not data:
  22                 break
  23             sys.stdout.write(data)
  24         connected_socket.close()
  25 except KeyboardInterrupt:
  26     pass
  27 s.close()

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.