| <<inapoi
la documentatie<<
Beej's Guide to Network Programming |
||
|---|---|---|
| Prev | Next | |
Well, guess what! I've already done this nasty business, and I'm dying to share the information with everyone! You've come to the right place. This document should give the average competent C programmer the edge s/he needs to get a grip on this networking noise.
Hopefully, though, it'll be just enough for those man pages to start making sense... :-)
$ cc -o server server.c -lnsl -lsocket -lresolv |
If you still get errors, you could try further adding a "-lxnet" to the end of that command line. I don't know what that does, exactly, but some people seem to need it.
As I don't have a Sun box, I haven't tested any of the above information--it's just what people have told me through email.
First, ignore pretty much all of the system header files I mention in
here. All you need to include is:
#include <winsock.h> |
Wait! You also have to make a call to WSAStartup() before doing
anything else with the sockets library. The code to do that looks something
like this:
#include <winsock.h>
{
WSAData wsaData;
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
fprintf(stderr, "WSAStartup failed.\n");
exit(1);
}
|
Once you do that, the rest of the examples in this tutorial should generally apply, with a few exceptions. For one thing, you can't use close() to close a socket--you need to use closesocket(), instead. Also, select() only works with socket descriptors, not file descriptors (like 0 for stdin).
To get more information about Winsock, read the Winsock FAQ and go from there.
Feel free to add your name and email address to the translation.
This guide may be freely reprinted in any medium provided that its content is not altered, it is presented in its entirety, and this copyright notice remains intact.
Educators are especially encouraged to recommend or supply copies of this guide to their students.
This guide may be freely translated into any language, provided the translation is accurate, and the guide is reprinted in its entirety. The translation may also include the name and contact information for the translator.
The C source code presented in this document is hereby granted to the public domain.
Contact <beej@piratehaven.org> for more information.