socket issue with recv()

dieter dieter at handshake.de
Sun Aug 24 01:59:34 EDT 2014


Arthur Clarck <aclarck5 at gmail.com> writes:
> ...
> The problem I have now is the following.
> I have a script to connect to some telecom service.
> The script is forking (parent/child)
> The child is only reading what comes from the remote server.
> Here the problematic code:
>
> total = ''
> while True:
>    data = s.recv(1024)
>    total += data
>    if (data == ''):
>       print 'remote site is closed'
>       s.close()
>       sys.exit()
>
> What is happening is that I got some datas from the remote site,
> Something like 'Contacting BH: ...'
> But directly followed by 'remote site is closed.

Some services (such as older HTTP 1.0 services) are designed
for "one command per connection" mode. This means, they answer
a signle command and then close the connection.

>From what you describe, your service might belong to this class.
In this case, you would need to open a new connection whenever
you detect that the old connection was closed.




More information about the Python-list mailing list