how do I include this header it says error in my system :(
thx for future help
Printable View
how do I include this header it says error in my system :(
thx for future help
hmmz it is a bit hard to tell because you didnt state your compiler :)
I use visual studio c/c++ :)
>I use visual studio c/c++
It's generally difficult to include Unix headers on a Windows system. Explain what you're trying to do and the answer will be more useful than "You can't do that".
oh okay then
I am trying to open a port , lisen ,read , write data to it :) any help would be great
Code:#include <winsock2.h>
Searching for "socket tutorial" or the like on this board or a search engine will give you a tutorial for winsock, or a tutorial for unix sockets and their differences from winsock sockets.
[edit] I like Beej's sockets tutorial: http://www.google.ca/search?hl=en&q=beej&meta= [/edit]
[edit=2] From http://mia.ece.uic.edu/~papers/WWW/s...tml/intro.html
[/edit]Quote:
1.5. Note for Windows Programmers
I have a particular dislike for Windows, and encourage you to try Linux, BSD, or Unix instead. That being said, you can still use this stuff under Windows.
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 this doesn't work
//WSAData wsaData; // then try this instead
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
fprintf(stderr, "WSAStartup failed.\n");
exit(1);
}
You also have to tell your compiler to link in the Winsock library, usually called wsock32.lib or winsock32.lib or somesuch. Under VC++, this can be done through the Project menu, under Settings.... Click the Link tab, and look for the box titled "Object/library modules". Add "wsock32.lib" to that list.
Or so I hear.
Finally, you need to call WSACleanup() when you're all through with the sockets library. See your online help for details.
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).
There is also a socket class that you can use, CSocket. Check your compilers help pages for more information.
To get more information about Winsock, read the Winsock FAQ and go from there.
Finally, I hear that Windows has no fork() system call which is, unfortunately, used in some of my examples. Maybe you have to link in a POSIX library or something to get it to work, or you can use CreateProcess() instead. fork() takes no arguments, and CreateProcess() takes about 48 billion arguments. If you're not up to that, the CreateThread() is a little easier to digest...unfortunately a discussion about multithreading is beyond the scope of this document. I can only talk about so much, you know!
There shouldn't be much differences though.
I have compiled many unix socket tutorials with no problems.
Although it doesn't hurt to learn the differences :)
cool thx people If I have any more questions I will ask :)
this tutorial is better for me And i hope it helps otherS too
http://www.exegesis.uklinux.net/gand...k/winsock1.htm
When I use this code I get the following 2 errorCode:#include <winsock.h>
int main(void)
{
WSADATA wsaData;
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0)
{
printf("WSAStartup failed.\n");
exit(1);
}
}
1)Error 2 error LNK2019: unresolved external symbol _WSAStartup@8 referenced in function _main ports.obj
2)Error 3 fatal error LNK1120: 1 unresolved externals C:\Documents and Settings\Ajay\My Documents\Visual Studio 2005\Projects\ports\Debug\ports.exe
>1)Error 2 error LNK2019: unresolved external symbol _WSAStartup@8 referenced in function _main ports.obj
You need to link the winsock library too. Just including the header doesn't do diddly because it only contains declarations.
It's mentioned here:
It's libwsock32.a for Dev-C++, I think; the command-line parameter is -lwsock32.Quote:
You also have to tell your compiler to link in the Winsock library, usually called wsock32.lib or winsock32.lib or somesuch. Under VC++, this can be done through the Project menu, under Settings.... Click the Link tab, and look for the box titled "Object/library modules". Add "wsock32.lib" to that list.
in visual studio I don't see any thing under that any help will be better pls
thx for future help
I got it working thxs every one