Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Q: simple sockets, bind, and socket error 10048

Reply
Thread Tools

Q: simple sockets, bind, and socket error 10048

 
 
Johannes Eble
Guest
Posts: n/a
 
      07-16-2003
Hello Python community,

I am trying the echo-client and echo-server examples in Chapter 10,
"Programming Python" by Mark Lutz.
It is probably the most simple sockets sample: A socket server just
echoing the socket clients' requests.

The program works so far. I first start the server in one dos box,
then the client in another dos box on my machine.

However, I wonder why the client always gets a new port. This is
printed in the server's dos box:

g:\WingIDE\profiles\Johannes Eble\sock>python echo-server.py
Server connected by ('127.0.0.1', 104
Server connected by ('127.0.0.1', 1049)
Server connected by ('127.0.0.1', 1050)
Server connected by ('127.0.0.1', 1056)
Server connected by ('127.0.0.1', 1057)
Server connected by ('127.0.0.1', 105

Note that I start a client one by one (in the same client's dos box).
It seems that the older port numbers can't be used anymore even if the
client is closing the connection and terminating.

I have tried to bind the client to port 4000. I can start the client
one time without an error. But the second time I get a socket error:

g:\WingIDE\profiles\Johannes Eble\sock>python echo-client.py
Client has socket address '127.0.0.1' 4000
Client received: 'Echo=>Hello network world'

g:\WingIDE\profiles\Johannes Eble\sock>python echo-client.py
Traceback (most recent call last):
File "echo-client.py", line 18, in ?
sockobj.connect((serverHost, serverPort))
File "<string>", line 1, in connect
socket.error: (10048, 'Address already in use')


I do not understand why the port is still in use. Why can't I define a
constant socket address for my client? Doesn't Python release the
client's port address as soon as the client calls close() on its
socket object or, at latest, when the client process terminates? I
have tried a

sockobj.shutdown(2)

on the client (before close() ) without an effect.


Any help would be great.


Regards


Johannes





 
Reply With Quote
 
 
 
 
Grant Edwards
Guest
Posts: n/a
 
      07-16-2003
In article <(E-Mail Removed)>, Johannes Eble wrote:

> Note that I start a client one by one (in the same client's dos
> box). It seems that the older port numbers can't be used
> anymore even if the client is closing the connection and
> terminating.


The port can't be used because it's still in use. When you
close a TCP connection, it doesn't go away immediately. It
goes into a "wait" state for several minutes just in case there
are packets belonging to that connection wandering around the
internet. If you want to skip that waiting state (a decision
which a small risk associated), set the SO_REUSEADDR option on
the socket.

> I do not understand why the port is still in use.


Stevens chapter 18:

http://www.amazon.com/exec/obidos/AS...800181-0657431

--
Grant Edwards grante Yow! I like the way ONLY
at their mouths move... They
visi.com look like DYING OYSTERS
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why sock.bind is always report 10048 error when in a script with multiprocessing Junfeng Hu Python 12 11-19-2011 02:45 AM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 0 02-01-2009 12:45 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM



Advertisments