setsockopt()

Started by
5 comments, last by TheRealBartman 20 years, 11 months ago
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
Michael BartmanLead ProgrammerDark Omen Studios
Advertisement
Ok, nevermind.

I figured it out.

thanks

Michael Bartman
Michael BartmanLead ProgrammerDark Omen Studios
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.
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
Michael BartmanLead ProgrammerDark Omen Studios
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


~ Tim
Yeah if you want to reuse sockets you need to be running Windows XP (or higher) and call DisconnectEx.
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
or you can call TransmitFile with null for file handler and buffers and specify the disconnect and re-use flags on Windows NT4.0 and 2000 :D

~ Tim
~ Tim

This topic is closed to new replies.

Advertisement