Advertisement
Guest User

Untitled

a guest
Mar 30th, 2011
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import socket
  4.  
  5. host = ''
  6. port = 8080
  7.  
  8.  
  9. c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  10. c.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  11. c.bind((host, port))
  12. c.listen(1)
  13. print 'WS has been started'
  14.  
  15. while 1:
  16.     csock, caddr = c.accept()
  17.     cfile = csock.makefile('rw', 0)
  18.     line = cfile.readline().strip()
  19.     cfile.write('HTTP/1.0 200 OK\n\n')
  20.     cfile.write('<html><head><title>Welcome %s!</title></head>' %(str(caddr)))
  21.     cfile.write('<body><h1>Follow the link...</h1>')
  22.     cfile.write('All the server needs to do is ')
  23.     cfile.write('to deliver the text to the socket. ')
  24.     cfile.write('It delivers the HTML code for a link, ')
  25.     cfile.write('and the web browser converts it. <br><br><br><br>')
  26.     cfile.write('<font size="7"><center> <a href="http://python.about.com/index.html">Click me!</a> </center></font>')
  27.     cfile.write('<br><br>The wording of your request was: "%s"' %(line))
  28.     cfile.write('ПРИВЕТ МИР') 
  29.     cfile.write('</body></html>')
  30.     cfile.close()
  31.     csock.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement