socket issue with recv()

Marko Rauhamaa marko at pacujo.net
Sat Aug 23 04:46:47 EDT 2014


Arthur Clarck <aclarck5 at gmail.com>:

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

This works:

========================================================================
#!/usr/bin/env python3

import sys, socket, os

def main():
    s = socket.socket()
    s.connect(("mail.python.org", 25))
    if os.fork() > 0:
        s.close()
        os.wait()
        os._exit(0)
    while True:
        data = s.recv(50)
        sys.stderr.write("{}\n".format(repr(data)))
        if not data:
            break

if __name__ == "__main__":
    main()
========================================================================


Marko



More information about the Python-list mailing list