Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Tags: TSQL, Created At: 10/24/2016 8:06:52 PMViews:

HTML view:
Copy Source | Copy HTML
  1. import socket
  2.  
  3. EOL1 = b'\n\n'
  4. EOL2 = b'\n\r\n'
  5. response = b'HTTP/1.0 200 OK\r\nDate: Mon, 1 Jan 1996 01:01:01 GMT\r\n'
  6. response += b'Content-Type: text/plain\r\nContent-Length: 13\r\n\r\n'
  7. response += b'Hello, world!'
  8.  
  9. serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  10. serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  11. serversocket.bind(('0.0.0.0', 8080))
  12. serversocket.listen(1)
  13.  
  14. connectiontoclient, address = serversocket.accept()
  15. request = b''
  16. while EOL1 not in request and EOL2 not in request:
  17.     request += connectiontoclient.recv(1024)
  18. print(request.decode())
  19. connectiontoclient.send(response)
  20. connectiontoclient.close()
  21.  
  22. serversocket.close()

Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2017