How can I free a port which was occupied by the old deaded progam?

  I develope a service program as a server which bind some udp ports. the system show failed message when sometime I stop the service from the service manager. And then the service is stoped, but the ports it used are not free. When I run the service again, the 10048 Error occurs, which means "the address and port have been used". How can I free those kind of ports.
IaskyouAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
swapsthegreatConnect With a Mentor Commented:
in your server program, when u create a socket and bind it to a particular port, this problem occurs.
To avoid this use the setsockopt() function to set socket level options to free the bound port immediately.

On Unix systems the call would be

setsockopt(sockdescr,SOL_SOCKET,SO_REUSEADDR,&on,sizeof(int));


sockdesc is socket descriptor
SOL_SOCKET says that options are set at socket level
SO_REUSEADDR allows u to reuse address and port
on is integer which is 1(to set).

Dont know much bout windows programming but i hear it is nearly the same
0
 
Steve JenningsIT ManagerCommented:
Depending on how the port connection failed, you may need to reboot to recover the port and the mbuf space. On one of the AIX systems here I have to craft a reset packet and send it as if it were actually coming from the connected machine.

What OS?

Good luck.
Steve
0
 
SunBowCommented:
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
SunBowCommented:
sounds like either bad OS (services not communicating with each other) or not waiting long enough for everything to sync back up.

> How can I free those kind of ports

Don't. Or rather, why?

Sounds like an ungraceful shutdown, or one that needs more grace.

Almost makes me want to know just which ports....

> I develope a service program as a server which bind

If it all began with your own development, then possibly you still have the control there. Whatever you open - try to close before exit (exit process should do it) (system should also detect the interruption, and run the graceful exit, not the one for debugging). Whatever you bind, unbind prior to exit.

Until then, I think the soft reboot is the quickest path to recovery.
0
 
Steve JenningsIT ManagerCommented:
. . . must be nice to work in an environment where you can just reboot to fix things . . .


Steve
0
 
IaskyouAuthor Commented:
oh, sorry, I forget reporting the OS.
win2000.
0
 
IaskyouAuthor Commented:
The machine is worked as server. So it can not be rebooted oftenly.
0
 
SunBowCommented:
Generally, for our production servers, we do not make a practise of stopping Win2K services, preferring what stability we can achieve.
0
 
SunBowCommented:
yeah, but a little tricky, and incompleteness can down all ports. not so good for someone's production server(s)
0
All Courses

From novice to tech pro — start learning today.