title: Sending HTML through Python Socket Server
body: <p>I am trying to learn some HTTP/CGI stuff and I want to print HTML on the webpage when you view it in your browser but am not sure what the correct syntax is when using the socket library:</p>
  
  <pre><code>#!/usr/bin/env python
  import random
  import socket
  import time
  
  s = socket.socket()         # Create a socket object
  host = socket.getfqdn() # Get local machine name
  port = 9082
  s.bind((host, port))        # Bind to the port
  
  print 'Starting server on', host, port
  print 'The Web server URL for this would be http://%s:%d/' % (host, port)
  
  s.listen(5)                 # Now wait for client connection.
  
  print 'Entering infinite loop; hit CTRL-C to exit'
  while True:
      # Establish connection with client.    
      c, (client_host, client_port) = s.accept()
      print 'Got connection from', client_host, client_port
      c.send('Server Online\n')
      c.send('HTTP/1.0 200 OK\n')
      c.send('Content-Type: text/html\n')
      c.send(' """\
          &lt;html&gt;
          &lt;body&gt;
          &lt;h1&gt;Hello World&lt;/h1&gt; this is my server!
          &lt;/body&gt;
          &lt;/html&gt;
          """ ')
      c.close()
  </code></pre>
  
  <p>The first three c.send lines work and then there is a syntax issue with the last line where I put in HTML.</p>