Needing help with sockets

Irmen de Jong irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Thu Jul 24 17:53:50 EDT 2003


Martin Dion wrote:

> Thank you for your reply, but I have not been able to find good information 
> about the select module for a client. Do you know a good place to find 
> tutorials about select module for clients ?

I'm not sure what you mean with 'select module for a client'...
What do you need to know that is not in the module documentation
or the Python socket howto?

Anyway have a look at the following mini example that I whipped up:

-------------
from select import select
from socket import *
import sys

sock=socket(AF_INET, SOCK_STREAM)
sock.connect( ('ftp.xs4all.nl', 21) )  # ftp port

print '>',    # prompt

while 1:
	ins, outs, exs = select([sys.stdin, sock], [], [])
	if sys.stdin in ins:
		userline=sys.stdin.readline()
		sock.send(userline)
		print '>',
	if sock in ins:
		socketdata=sock.recv(1000)   # buffer = 1000
		if socketdata:
			print socketdata,
		else:
			break   # no more data

-------------

Does this help? If not, please describe in more detail what you
want to achive, what you've already tried and why that didn't work.

Good luck!

--Irmen de Jong





More information about the Python-list mailing list