🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

closesocket

Started by
7 comments, last by avianRR 22 years, 10 months ago
I''m working on a multi-platform application that currently runs under both win32 and linux. I''ve run into a little problem with the close socket command though. It dosn''t seem to exist in linux. I found one sample that just used close(socket_descriptor) but that dosn''t work eather. If anyone can shed some light on this subject I''d appreciate it.
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
Advertisement
Hi.. here is my contribution... it may be useless or it may work im not pro at this subject yet..

if you not already try using shutdown to tell the client socket that its closing..

shutdown(Socket, SD_BOTH)
closesocket(Socket)


-Tim
~ Tim
I''m not positive but I think the command under Linux is:

close(socket);

You should almost always call shutdown(socket, SD_BOTH) first.



Dire Wolf
www.digitalfiends.com
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
Thanks, never heard of the shutdown function, never seen in mentioned in any of the references I''ve read eather. It answered a few questions on stuff that talked about gracefull shutdowns of the socket though!

the reason close(socket) wasn''t working was because I forgot a header file.

I tried using shutdown but I got an error durring compile...
error C2065: ''SD_BOTH'' : undeclared identifier
I get the undeclared identifyer under win32 and linux despite the fact the it says in the documentation for both systems that that''s the parameter to use. any ideas???
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
SD_BOTH = 2

tim
~ Tim
Yeah, I had the same problem. I don''t know why they don''t define SD_BOTH. Kind of silly.



Dire Wolf
www.digitalfiends.com
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
I found them defined in winsock2.h and you have to force adding it by putting #include < winsock2.h > before #include < windows.h > or you'll get errors. In windows.h it's decided wich to include as follows...

#if(_WIN32_WINNT >= 0x0400)
#include
#include
#else
#include
#endif /* _WIN32_WINNT >= 0x0400 */

but apparently it never choses to and I don't know where the _WIN32_WINNT value is defined so I don't know how to change it.

I still can't find the file that there defined in under linux though!

Thanks for the help...

Edited by - avianRR on August 27, 2001 4:00:19 AM

Edited by - avianRR on August 27, 2001 4:01:51 AM
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
quote: Original post by avianRR
I still can''t find the file that there defined in under linux though!

That''s because the SD_* constants aren''t defined under Linux. Either use ''2'' directly (which is what SD_BOTH stands for), or define them directly yourself: copy the #defines out of the Winsock header, and put them in the #ifdef linux block (or whatever it is for your linux compilation).

quote: Original post by Kylotan
Either use ''2'' directly (which is what SD_BOTH stands for), or define them directly yourself: copy the #defines out of the Winsock header, and put them in the #ifdef linux block (or whatever it is for your linux compilation).


That''s what I did copyed the #defines from the winsock headder to the linux section of the platform specific header includes. I hate haveing to do something that way but it seams to work.


-----------------------------------------------------------------
http://tannara.net/
And comming soon http://tannarasoft.com/ makers of great games
Also Comming soon "Warlords", "StarLords", "Legends Of Tannara"
and many other great games

"Only when you understand what it is that you don''t understand will you truly understand!"
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]

This topic is closed to new replies.

Advertisement