Difference: BasicWEBServer (2 vs. 3)

Revision 32022-11-12 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WEBServer"

Writing a WEB server from scratch

Changed:
<
<
We do not want to re-invent the wheel and we will use a WEB server already prepared for us by professional programmers but it is nevertheless interesting to implement a very simplistic WEB server ourselves simply to understand the basic principles.
>
>
We do not want to re-invent the wheel, and we will use a WEB server framework already prepared for us by professional programmers. It is nevertheless interesting to implement a very primitive WEB server ourselves, simply to understand the basic principles.
 

The Hello World WEB Server

Changed:
<
<
Let's start simple and produce a WEB server that just sends "Hello World!" to the browser when called. You may add some HTML text if desired. In the first version we will write a TCP server creating a stream socket and binding to port 80.

>
>
Let's start simple and produce a WEB server that just sends "Hello World!" to the browser when called. You may add some HTML text if desired. In the first version we will write a TCP server creating a stream socket and binding to port 80.

 
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) 
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 
try:
Line: 21 to 23
 while True: conn,addr=s.accept() print("GOT a connection from %s" % str(addr))
Changed:
<
<
Finally it reads an http request from the connection and answers with its Hello World page:
>
>
Finally, it reads an HTTP request from the connection and answers with its Hello World page:
 
request=conn.recv(1024)
print("Content %s" % str(request))
Changed:
<
<
request=str(request) response=html conn.send(response) conn.close()
>
>
request=str(request) response=html conn.send(response) conn.close()
 
Changed:
<
<
html is the http string to be sent, e.g.
>
>
HTML is the HTTP string to be sent, e.g.
 
html = """ <!DOCTYPE html>
<html>
<head>
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback