-
January 17th, 2000, 06:50 PM
#1
Error when closing a socket and reconnecting
Following problem:
I created a Socket (CSocket instance), bound it and connected to host.
After data exchange, I closed the Socket (x.close ())
Now, I want to reuse this Socket to establish a new connection to another host - but the programm terminates with an assert.
Is the socket still in use, even if call x.close() ?
(I also tried x.ShutDown (2) - same problem!)
How can I close/free the socket?
-
January 19th, 2000, 03:02 PM
#2
Re: Error when closing a socket and reconnecting
Do the following after you've called CSocket::Create() and before you call CSocket::Accept(). If you call CSocket::Bind()(doesn't look like it), do the following before Bind().
CSocket mySocket;
mySocket.Create(...);
....
int nOptionValue = 1;
int nOptionLen = sizeof(nOptionValue);
mySocket.SetSockOpt(SO_REUSEADDR, (void *)&nOptionValue, &nOptionLen, SOL_SOCKET);
...
mySocket.Accept(...);
....
Kailash
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|