linking error / winsock.h

[b][red]This message was edited by core at 2003-12-5 14:7:55[/red][/b][hr]
hi!

i just started programming little client / server application, and i am quite new to this. When i tried to compile server.c or client.c, i get this error messages:

--------------------Configuration: client - Win32 Debug--------------------
Linking...
client.obj : error LNK2001: unresolved external symbol [email protected]
client.obj : error LNK2001: unresolved external symbol [email protected]
client.obj : error LNK2001: unresolved external symbol [email protected]
client.obj : error LNK2001: unresolved external symbol [email protected]
client.obj : error LNK2001: unresolved external symbol [email protected]
client.obj : error LNK2001: unresolved external symbol [email protected]
client.obj : error LNK2001: unresolved external symbol [email protected]
client.obj : error LNK2001: unresolved external symbol [email protected]
Debug/client.exe : fatal error LNK1120: 8 unresolved externals
Error executing link.exe.

client.exe - 9 error(s), 0 warning(s)

Can anyone help me please?


Source:

#include
#include

#define PORT 23444

struct sockaddr_in my_adresse, remote_adresse;
int groesse, return_value;
SOCKET sock, remote_sock;
WSADATA ws;

int main( int argc, char *argv[]) {
// Hauptroutine

WSAStartup(0x0101,&ws);

// Socket anfordern
sock = socket(AF_INET, SOCK_STREAM, 0);
if(sock < 0) {
printf("Fehler beim Erzeugen des Socket. Programm wird beendet!");
return(-1);
}

// Socket zurechtschnitzen
my_adresse.sin_family = AF_INET;
my_adresse.sin_port = htons(PORT);
my_adresse.sin_addr.s_addr = INADDR_ANY;

// Socket binden
if(bind(sock,(struct sockaddr *)&my_adresse, sizeof(my_adresse)) == -1) {
printf("Fehler beim Binden des Sockets. Programm wird beendet!");
return(-1);
}

// Bester Zeitpunkt, um zu warten ;-)
if(listen(sock,1) == -1) {
printf("Fehler beim Warten auf eine Verbindung. Programm wird beendet!");
return(-1);
}

groesse = sizeof(remote_adresse);

remote_sock = accept(sock, (struct sockaddr *)&remote_adresse, &groesse);
if(remote_sock < 0) {
printf("Fehler beim Akzeptieren einer Remote-Verbindung. Programm wird beendet!");
return(-1);
}

printf("Sende Daten...

");

groesse = send(remote_sock,"Hallo Client!", 13, 0);
if(groesse == -1) {
printf("Fehler beim Senden der Daten!

");
} else {
printf("Gesendete Bytes: %d

",groesse);
}

printf("Schliesse Verbindung...");

closesocket(remote_sock);
closesocket(sock);

WSACleanup();
return(0);
}


Comments

  • you have to include winsock32.lib in your project. Win32 may need ws2_32.lib
  • [b][red]This message was edited by core at 2003-12-8 6:42:7[/red][/b][hr]
    : you have to include winsock32.lib in your project. Win32 may need ws2_32.lib
    :

    yeah, that's it ... took a time till i found it in dev-c++, but now it works just fine. ( the library is called 'libwsock32.a' )
    it worked out before in vc++ 6.0, but after having installed some freeware / shareware editors / ide's, i got this error.

    thanks a lot :)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories