Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"couldn't open socket: address already in use " socket programming

Status
Not open for further replies.

adekunleadekoya

Programmer
May 19, 2008
30
I have this error "couldn't open socket: address already in use " whenever i close my wish windows running this code below and i try to source the program again.

Does it mean that the socket was not gracefully closed ? How could i do dat ? Am just learning tcl/tk with a plan to develop a network application with d language. so i need to get at d basics of d language in no time.

any help will be appreciated. [ See my sample code below]


/*******************************
socket -server Accept 8000

proc Accept {newSock addr port} {
puts "Accepted $newSock from $addr port $port"
puts $newSock "goodbye"
flush $newSock
close newSock
}

****************************/
 
What's happening on the client side?

_________________
Bob Rashkin
 
What i notice is that the client seems not to be an issue. i have the same problem when there is never a connection from any client.

the point seems to be that closing the wish window where the server is running rarely closes the listening server socket. It seems that the server sockets keeps listening after the wish window is closed. Is it possible that the socket's lifetime transcends the wish window's ?

And can I force graceful shutdown/closing of the server/listening socket ?




 
I suspect that the client is never an issue. I do have this problem even when there is never a connection with the client.

I suspect that the listening sockets stays alive long after the wish window is closed. Is this possible ?

And how can one forecfully close the server socket in situations where the wish windows is terminated abruptly ?

Can a sginal be sent to my server application to close the listening socket when the wish window is closing ?

Or there are socket options that may be invoked to ensure that the lifetime of a socket never transcends the wish window's ?


Any good help will be appreciated



 
Well, now that I look again, there's a syntax error in your sample code posted.
close newSock
should be
Code:
close [red]$[/red]newSock

If that was just a typo, then your code seems ok to me; the socket should close by command.

_________________
Bob Rashkin
 
yes it was a typo.

I still have similar experience. What could be wrong ?

excellent insights/leads will be appreciated


tanks



 
note that running the same sample code with tcl interpreter works fine but for wish interpreter.

my version of wish is 8.5 which i always invoke with wish85

hope these may help any person that can assist. my ultimate app will be a windows based application. so wish will surely be the target interpreter for my application

 
I don't see anything wrong with your script. That leads me (however erroneously) to suspect your environment. Try putting delays before and after the close command. Maybe the flush (which I'm not even sure is necessary) is taking longer than is tolerable by the interpreter.

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top