Socket Programming Without Windows
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.
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.
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.
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*
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.
#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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement