Python Forum
Socket won't receive data suddenly with multiple clients
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Socket won't receive data suddenly with multiple clients
#1
Hi Folks,

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
...
...
...
Reply


Messages In This Thread
Socket won't receive data suddenly with multiple clients - by SquareRoot - Sep-06-2017, 09:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Socket to stream data and tranmit and revieve data kiyoshi7 0 2,426 Aug-11-2022, 10:52 PM
Last Post: kiyoshi7
  how to split socket data onto multiple clients for separate processing ConcealedFox70 0 1,990 Jan-11-2022, 08:26 PM
Last Post: ConcealedFox70
  socket without blocking loop and automatically retrieve data from the port RubenP 3 3,682 Jun-21-2020, 10:59 PM
Last Post: Gribouillis
  TCP socket, data transnission Simba 4 3,339 Dec-07-2019, 03:15 PM
Last Post: Simba
  Chat box locking up with multiple clients running Clunk_Head 1 2,039 Nov-27-2019, 04:13 PM
Last Post: Clunk_Head
  Soft Access Point & Socket Data Streaming groger57 1 2,594 Aug-01-2019, 02:53 PM
Last Post: groger57
  How to send/receive data over TCP Rehan11 1 3,782 Feb-01-2019, 11:21 AM
Last Post: cetpaseo336
  Multiple network socket servers? MuntyScruntfundle 1 2,534 Nov-13-2018, 03:46 PM
Last Post: wavic
  Send data BMP180 between client and server trought module socket smalhao 0 2,888 Jul-30-2018, 12:56 PM
Last Post: smalhao
  How to support multiple users with heavy data processing Gingmeister 3 3,113 Jun-19-2018, 05:00 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020