472,353 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Q: simple sockets, bind, and socket error 10048

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', 1048)
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', 1058)

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

Jul 18 '05 #1
1 8875
In article <3f**************@news.online.de>, 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
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Clarence Gardner | last post by:
I've got a problem that I don't see how to program around. A socket server that was running fine, today started getting an exception from the bind()...
0
by: Darren Thomas | last post by:
Dear all, I have written a TCP server as a windows service that accepts connections using the System.Net.Sockets.Socket class. I use the various...
1
by: Guillaume Kaddouch | last post by:
Hi, I am in trouble since many days because i'm facing a problem that i can't solve. I used to play with RAW socket under Linux, but the near...
4
by: 0to60 | last post by:
I have a question about socket programming in general. Exactly what happens behind the scenes when I one socket connects to a different socket in...
0
by: Gregory Hassett | last post by:
Hello, I want to periodically send a TCP packet to a peer, always from the same source port. That is, each packet will come from my local ip...
1
by: verge | last post by:
hello everyone! how's it going? like everyone in here im in need of some help and good friendship along the way...take a look at this: ...
2
by: Vitali Gontsharuk | last post by:
Hi! I have a problem programming a simple client-server game, which is called pingpong ;-) The final program will first be started as a server...
0
by: J008 | last post by:
Just looking for some insight as to why the callback "BeginReceiveFromCallback" is not being called in my "Receive" Subroutine below (when I call...
1
by: MaheBytes | last post by:
I have been facing a problem with UDP socket programming. I have to reuse port number for two different IP address. I am actually using SO_REUSEADD....
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.