socket.recvfrom() & sendto()

Ron Johnson ron.l.johnson at home.com
Mon May 7 14:11:16 EDT 2001


Cary O'Brien wrote:

> In article <VFrJ6.35380$2U.14656610 at news2.rdc2.tx.home.com>,
> Ron Johnson  <ron.l.johnson at home.com> wrote:
>>Hello,
>>
>>Can these be used by a server process that wants to simultaneous
>>keep sockets open to multiple clients?
>>
> 
> Sure.  You can have as many open sockets as you want (within
> reason, i.e. hundreds [1].  With thousands of open connections
> you may run into problems).

The mis-understanding that I am having is that you can only bind 
one socket to a server:port.  Ergo, how do have multiple sockets
open at the same time?

>>> import socket, select
>>>
>>> sock1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> sock1.setsockopt(socket.SOL_SOCKET,  socket.SO_REUSEADDR, 1)
>>> sock1.setblocking(0)
>>> sock1.bind((socket.gethostname(), 50000))
>>> sock1.listen(5)
>>>
>>> sock2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> sock2.setsockopt(socket.SOL_SOCKET,  socket.SO_REUSEADDR, 1)
>>> sock2.setblocking(0)
>>> sock2.bind((socket.gethostname(), 50000))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
socket.error: (98, 'Address already in use')

Sincerely,
Ron
-- 
 Ron Johnson, Jr.        Home: ron.l.johnson at home.com
 Jefferson, LA  USA      http://ronandheather.dhs.org
 "Is Python better or worse than Perl?"
  "Perl is worse than Python because people wanted it 
   worse." -Larry Wall, 10/14/1998



More information about the Python-list mailing list