Socket Programming Without Windows

Started by
4 comments, last by hplus0603 17 years, 4 months ago
I have a server app that I need to port to Linux. I removed all references to windows.h. Also, the app does not need to keep time so GetTickCount and QPC are not needed. I think the only trouble GCC has with my code is the networking socket stuff. GCC does not find the "winsock2.h" and "ws2tcpip.h" headers that I am using. I'm also using the wsock32.lib library. What headers and libraries to I need to reference for Linux? I'm assuming most of the function calls will be the same because everything is using Berkley sockets, right? Anything specific I will have to change? Thanks for any help.
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog
Advertisement
Sockets are usually part of libc; if not, it's typically -lsocket.

Typically, you use <sys/socket.h> and <sys/types.h> to get sockets.

In general, on Linux, if you want to know how to use function X, the easiest thing to do is to just "man X," and at the top, there will be a synopsis, which tells you what to include.
enum Bool { True, False, FileNotFound };
Quote:Original post by hplus0603
Sockets are usually part of libc; if not, it's typically -lsocket.

Typically, you use <sys/socket.h> and <sys/types.h> to get sockets.

In general, on Linux, if you want to know how to use function X, the easiest thing to do is to just "man X," and at the top, there will be a synopsis, which tells you what to include.


Awesome, thanks. I've been thinking that if I get the headers right, the code will just compile and work. *Crosses fingers*
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog
Not really, do do linux / windows cross platform networking (in code) you typically have a lot of:

#if defined (__WIN32)

#elseif defined...

#endif

Windows uses the winsock libs, Linux, vxworks etc have the same effects but normally slightly different config / names for each methods so a straight port is likely to fail.
Quote:Original post by Lord Darkblade
Not really, do do linux / windows cross platform networking (in code) you typically have a lot of:

#if defined (__WIN32)

#elseif defined...

#endif

Windows uses the winsock libs, Linux, vxworks etc have the same effects but normally slightly different config / names for each methods so a straight port is likely to fail.


Just a few small differences in type names (can be typedef-ed), in the constants (remove WSA), and in the closesocket() being called close() (define an alias).
Making a socket non-blocking is different between platforms as well (as Windows doesn't have fcntl())

I have a header called sock_port.h (or something similar) which takes care of the differences. I think that header is part of some of my socket sample code, such as Etwork.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement