Advertisement
Guest User

python web server

a guest
Feb 17th, 2016
133
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import socket
  2.  
  3. HOST, PORT = '10.0.0.4',4444
  4.  
  5. listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  6. listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  7. listen_socket.bind((HOST, PORT))
  8. listen_socket.listen(1)
  9. print 'Serving HTTP on port %s ...' % PORT
  10. while True:
  11. client_connection, client_address = listen_socket.accept()
  12. request = client_connection.recv(1024)
  13. print request
  14.  
  15. http_response = """\
  16. HTTP/1.1 200 OK
  17.  
  18. Hello, World!
  19. """
  20. client_connection.sendall(http_response)
  21. client_connection.close()
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement