Archived

This topic is now archived and is closed to further replies.

TheRealBartman

setsockopt()

Recommended Posts

Hey, I have a winsock networking class that works nearly perfectly for my needs. However, shortly after I recieved MS Visual Studio .NET, I noticed that my socket''s were not being reused after they have been closed. Inside the constructor of the networking class, I have the following code: ... setsockopt(iDesc, SOL_SOCKET , SO_REUSEADDR, &yes, sizeof(int)); ... To my knowledge, this should reuse sockets, at least it did previously. After I am done with a socket, I always perform a closesocket() on it so I am sure that isn''t the problem. If you need to see some of the code, I will post it here. Thanks, Michael Bartman

Share this post


Link to post
Share on other sites
quote:
Original post by TheRealBartman
Ok, nevermind.

I figured it out.
For archival reasons, its good practice to give the solution for a question you''ve asked and solved, so others having same or similar issues can learn.

Share this post


Link to post
Share on other sites
It was a problem specific to my custom code, nothing to do with winsock at all.

I will state how I fixed it anyway, though.

My entire project is based on C++ Object Orientation, and I use a lot of pointers.

VS .NET handled some of my pointers differently than VS 6 did, for some reason.

A pointer was being free''d that a method of my network class needed when a player disconnected. This caused a few problems, I just had to change the way some of my pointers were handled.

Michael Bartman

Share this post


Link to post
Share on other sites
Errr...
Actually the SO_REUSEADDR is nothing to do with resuing sockets. read the MSDN documenttation http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcewinsk/htm/_wcesdk_setsockopt.asp

It actually enabled binding to an address and port which is already bound (which can cause unpredicatable results)

quote:
Original post by TheRealBartman
Hey,

I have a winsock networking class that works nearly perfectly for my needs.

However, shortly after I recieved MS Visual Studio .NET, I noticed that my socket''s were not being reused after they have been closed.

Inside the constructor of the networking class, I have the following code:

...
setsockopt(iDesc, SOL_SOCKET , SO_REUSEADDR, &yes, sizeof(int));
...

To my knowledge, this should reuse sockets, at least it did previously.

After I am done with a socket, I always perform a closesocket() on it so I am sure that isn''t the problem.

If you need to see some of the code, I will post it here.

Thanks,


Michael Bartman



Share this post


Link to post
Share on other sites