Skip to main content
GameDev.net gamedev.net
🔒 Locked

Basic Networking With DEV-Cpp

Started by RainbowInBlack May 3, 2005 at 2:06 PM 5 replies 1.8k views
Original Post
RainbowInBlack
RainbowInBlack
I've Read The Beej's Network Programming Guide And made a Basic network Code in DEV-Cpp :
#include <winsock.h> 

int main() 
{ 
    WSADATA WSAData; 
    int server; 
    WSAStartup(MAKEWORD(1,0), &WSAData); 
    int port = 6666; 
  
    SOCKADDR_IN sinserv; 
    sinserv.sin_family=AF_INET; 
    sinserv.sin_addr.s_addr=INADDR_ANY; 
    sinserv.sin_port=htons(port); 
    server=socket(AF_INET,SOCK_STREAM,0); 
    bind(server,(SOCKADDR*)&sinserv,sizeof(sinserv)); 
    listen(server,0); 
}

and i got the compiling errors:
Quote:
[Linker error] undefined reference to WSAStartup@8' [Linker error] undefined reference to htons@4' [Linker error] undefined reference to bind@12' [Linker error] undefined reference to socket@12' [Linker error] undefined reference to `listen@8' ld returned 1 exit status
What was i doin wrong? Roy
happybara
happybara
add the following line to linker parameters
-lws2_32
Dolphins - The sharks of the sea.
RainbowInBlack
RainbowInBlack
Wow!
it worked!
:):):)

can i know what that line did?
"-lws2_32"?

Roy
MaximusCranius
MaximusCranius
Quote:
Original post by RainbowInBlack
Wow!
it worked!
:):):)

can i know what that line did?
"-lws2_32"?

Roy

It links the Winsock2 library.
hplus0603
hplus0603
In addition, you want to include instead of , and you want to include that before you include .

Also, you want to call WSAStartup() with version 2,2 of WinSock, instead of the 1,0 you have there now. Version 1,0 was very buggy, and when you say you want version 1,0, you get all the bugs, too.
enum Bool { True, False, FileNotFound };
RainbowInBlack
RainbowInBlack
OK, Thanks

BTW
what changed in winsock2? (in the function names, and every thing)
i can still use the same "socket","bind","send", etc functions?

Roy
hplus0603
hplus0603
Yes, you can still use the same functions; you just will get more of the behavior you'd expect and less of behavior that goes against the documentation.
enum Bool { True, False, FileNotFound };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.