Sep-06-2017, 09:09 PM
Hi Folks,
i've programmed a simple web server. This is the Code:
So my Question is: why isn't the function cfile.readline() receiving data? What is the Problem?
Thanks in advance,
SquareRoot
PS: Console Output on error:
accepted client
read file
GET / HTTP/1.1\r\n
read file
Host: localhost:8000\r\n\r\n
accepted client
read file
read file
read file
read file
read file
...
...
...
i've programmed a simple web server. This is the Code:
import socket csock='' c='' c = createListenSocket('',8000,1) cfile= '' page='' while 1: csock, caddr = c.accept() print 'accepted client' line = '' cfile = csock.makefile('rw', 0) while line != "\r\n": print 'read file' line = cfile.readline() print line if line == 'GET / HTTP/1.1\r\n': page = 'index' if page == 'index': cfile.write('HTTP/1.0 200 OK\n\n') cfile.write('Hello World!') cfile.close() csock.close() page=''If there is only one client, then it works perfectly. I can reload as often as i want in the client (Firefox), and there is always "Hello World" on the screen. However, when there are more than i client, it can happen that on client reload the page and sends his request to my script, and the script prints "accepted client" and then it prints "read line" all the time and the function cfile.readline() is always returning nothing. so the variable line always stays open.
So my Question is: why isn't the function cfile.readline() receiving data? What is the Problem?
Thanks in advance,
SquareRoot
PS: Console Output on error:
accepted client
read file
GET / HTTP/1.1\r\n
read file
Host: localhost:8000\r\n\r\n
accepted client
read file
read file
read file
read file
read file
...
...
...