help!! Networking Programming in C (Windows/Linux)
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
help!! Networking Programming in C (Windows/Linux)
hello,
I am learning Networking Programming in C. I am reffering Unix Network Programming vol 1 (W. Richards Stevens).i want to run the code given in this book on windows platform, if it is possible pls let me know.
i am also not able to compile those programs on Linux (Red Hat 9.0) system on gcc , it gives some "struct..... type error".
i also want to know,a network application made on Linux/Unix enviorment will work for windows or not.
Network programming is very similar between UNIX and Windows. One major difference is that under Windows you have to start and stop Winsock. If you paste the code I'd be able to tell you more.
You need to get the code that Stevens uses in his book, because the #include "unp.h" contains his wrapper functions, he talks about them in the book (Chapter 2 I think)
Alternatively you could rewrite the code not to use his wrapper functions, that will help you to better understand the socket interface and when you move it over to Windows the transition will probbaly be easier.
Hi, If you tell me email i can send you a complete server/client application example that works in Linux/BSD.
Windows has the same sockets like Linux because they both use BSD network sockets. But windows has an additional "upgrade" level, and some structs and functions has diferences because this "upgrade".
Give an email and i will send you a real working example.
From the above source code i can't see some needed include files and definitions. May be they are in unp.h but may be not.
To work with sockets in linux and windows you need this include files included:
/* OS dependent include files */
#if defined __LINUX__
#include <sys/un.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/stat.h>
#elif defined __WINDOWS__
#include <winsock.h>
#endif
As you can see there are some include files for the linux version and a one include file for a windows version.
Some of the linux include files are not needed but i use it in my application. The required files for linux are : "sys/socket.h", "netdb.h", "arpa/inet.h".
here are some standalone linux examples. They do not need wrappers etc and show the basics.
Quote:
Originally Posted by vibhory2j
i also want to know,a network application made on Linux/Unix enviorment will work for windows or not.
According to the other posts, it should not be difficult to write them platform independent. Just be aware that you need to recompile for (or on) the platform; simple copying of the executable will not work.
Last edited by Wim Sturkenboom; 07-20-2006 at 04:02 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.