Advertisement
thiagobodruk

Python HTML Server

Dec 20th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. import socket,codecs
  2.  
  3. host = '192.168.0.6'
  4. port = 80
  5. conns = 5
  6.  
  7. # Start Socket Server
  8. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  9. s.bind((host, port))
  10. s.listen(conns)
  11.  
  12. print('Starting Python Server...\n')
  13.  
  14. # HTML Response
  15. file = open('html/index.html','r')
  16. html = file.read()
  17. html = html.encode('utf-8')
  18.  
  19. # Listen for Connections
  20. while True:
  21.     conn, addr = s.accept()
  22.     buff = conn.recv(1024)
  23.     conn.send(html)
  24.    
  25.     if len(buff) > 0:
  26.         print(buff.decode('utf-8'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement