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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

More CSocket help needed 1

Status
Not open for further replies.

bitbit

Programmer
Nov 14, 2002
14
0
0
US
Hi, does anyone have any experience with using the SetSockOpt() function when using CSocket/CAsyncSocket ???

Here's my problem: I've successfully got a client and server to talk to each other (yay!). However, say I log off the client and then try to reconnect, I just get an error saying that the address is already in use!
I have to manually disconnect from internet and reconnect before it will work again.

From what I understand (and I could be wrong) I need to use the CAsyncSocket::SetSockOpt() function to pass SO_REUSEADDR to the socket to cure this problem.

However, this presents yet another problem: I think I'm supposed to call this function BEFORE the socket is bound to the address. However, I can't because Bind() is called during creation!

Does anyone know how I can cure this reusing address problem? Thanks
 
It's not you SetSockOpt you need to look at - you need to call WAECleanup() after you close the connection just like you have to initialize sockets with WAEStartup() before you connect.
What's happening is that the DLL that implements winsock is still hogging the resources for this address/port. So it needs to be released/cleared when your client app exits or closes the connection.

:)
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Man... that worked better than tylenol!!!! Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top