I can't create a socket no matter what i do! Must i have an internet connection to do that? .....
I'm using Windows by the way. Please take it easy, just yesterday i started socket programming!...
I can't create a socket no matter what i do! Must i have an internet connection to do that? .....
I'm using Windows by the way. Please take it easy, just yesterday i started socket programming!...
Devoted my life to programming...
Have you tried any of the sample code from the tutorials?
No you don't need an internet connection but you do need a network card.
Basically it's a stepwise process...
1) Get a socket handle with the socket() call.
2) Get your local IP address using one of the host lookup functions (eg. gethostbyname())
3) Set the desired port into the resulting sockaddr struct using htons(port).
4) Bind the socket using bind()
5) listen for connections with listen() or wait for news with recvfrom() (for udp)
You will definately find UDP communications a whole lot easier for your first project. Your best bet is to do the steps one at a time testing for success after each function call. Once the first is working, move on to the second and so on...
Hope that helps...
Thanks "CommonTater". My problem is that socket() always returns -1! I do have a network card so with what you said i can't see where's the problem. Maybe i'm passing wrongs parameters to the function? I do this:
and "sID" is always -1!!!Code:sID = socket(AF_INET , SOCK_DGRAM, 0);
Devoted my life to programming...
I think i found the problem. I didn't know i had to initialize winsock before using it!
Devoted my life to programming...
You need WSAStartup().
Post your code if the problem isn't resolved.
Check out MSDN.
Stop bumping old thread
CLOSED