Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
155 user(s) are online (132 user(s) are browsing Forums)

Members: 0
Guests: 155

more...

Support us!

Headlines

 
  Register To Post  

(solved) Why network listen socket not release port if Recv() is used?
Home away from home
Home away from home


See User information
I'm trying to do some very basic network stuff: Listening on a localhost port for a web browser to try to connect, and once it does my program quits. But it never seems to free it's port, so the next time my program runs, it fails to Bind() to the same port. And I can't work out why :(

Everything seems to be fine UNLESS I try to Recv() the message sent by the web browser. If I do that, then the port isn't freed, even though my program quits.

This seems to go against all the documentation, which claims that this kind of stuff should be freed by CloseSocket() and will definitely be freed when the library base is closed.

If it helps, the flow of my program is something like this:

OpenLibrary()
socketS = Socket()
Bind(socketS)
Listen(socketS)
socketC = Accept(socketS)
Recv(socketC)
CloseSocket(socketC)
CloseSocket(socketS)
CloseLibrary()

I've basically followed BSD examples (which often don't do a good job of closing stuff), so I'm wondering if I've missed a vital step when tidying-up.

EDIT: Never mind. Seems this problem is not what I thought it was, and it occurs on other platforms as well. For some strange reason I have to set SO_REUSEADDR to TRUE before I can reuse a localhost port.

EDIT: Using SO_REUSEADDR can apparently have unexpected side-effects, so I'm going to try using SO_REUSEPORT instead.


Edited by ChrisH on 2016/7/29 22:20:44
Edited by ChrisH on 2016/8/7 15:09:54
Author of the PortablE programming language.
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project