socket troubles

Sean Conley sconley at cs.csubak.edu
Mon Feb 14 09:50:47 EST 2000


	I am connecting to a telnet site.  The reason I left the address and
port in the code is that this particular one doesn't do any telnet
arbitration, since this application will definately hang if I try to
connect to a "real" telnet server until I get the arbitration done.  So
in essence the server is somewhere on the internet, since this is going
to basically be a modified telnet client.  

Sean

Sandra Plahl wrote:
> I wonder how you could ever read from the socket when you never could
> send???
> 
> I don't know if you have one but thats what you need is s second
> application (server), which is reading your send and reply on it. The
> answer then can be read from your first application (client). In the
> server try something like this:
> (its a socket skeleton from a daemon process)
> 
> import socket, sys, errno
> .....
> .....
> 
> serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
> serversocket.bind((HOST, PORT))
> serversocket.listen(5)
> while(1):
>     clientsocket = None
>     done = 0
>     while not done:
>         try:
>             (clientsocket, address) = serversocket.accept()
>         except socket.error, args:
>             if args[0] != errno.EINTR:
>                 raise
>         else:
>             done = 1
> 
>     cpid = os.fork()
>     if not cpid:
>         serversocket.close()
>         data = clientsocket.recv(80)
>         # Here you can do what you want with the send data
>         # Maybe send it back
>         clientsocket.send(data)
>         clientsocket.close()
>         data = None
>         sys.exit(0)
>     else:
>         clientsocket.close()
> 
> Sandra



More information about the Python-list mailing list