Link to home
Start Free TrialLog in
Avatar of Cryptos
Cryptos

asked on

Problems with winsock2.h

Hello

im trying to program a client server model in C++ and wanted to do this with winsock2.h. But it doesnt seem to be able to find this in MSVC++ 6.0. Or are the functions wrong here a sample code:


pubcomm::pubcomm()
{

}


pubcomm::~pubcomm()
{

     pubcomm::close();
}


void pubcomm::close(){
     //cleanup pubcomm datas
     shutdown(sock,SD_BOTH);
     closesocket(sock);
}

char* pubcomm::IP_CLIENT="123.456.789.000";
char* pubcomm::IP_SERVER="123.456.789.000";
int pubcomm::PORT_CLIENT=1024;
int pubcomm::PORT_SERVER=1024;


Any suggestions?

or even a sample code that works for this problem?

All the best

C
Avatar of jkr
jkr
Flag of Germany image

You have to either

#include <winsock.h>
#include <winsock2.h>

also or

#define INCL_WINSOCK_API_PROTOTYPES
#include <winsock2.h>
Avatar of Cryptos
Cryptos

ASKER

both does not work....

my includes:

#include <stdlib.h>
#include <stdio.h>

#include <vector>
#include <cmath>
#include <iostream>
#include <winsock2.h>

It seems to be a linking problem... do I have to change sth on the makefile?

Thanks

C
Avatar of Cryptos

ASKER

And of course Im using std as namespace...
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
your ip addresses are wrong!

you just can't use anything.

apart from that code looks ok.

send us the part you are trying to connect or bind/listen.

Avatar of Cryptos

ASKER

ok the ip adresses are certainly wrong. but thats not the problem. this cant check the compiler I think.

The pragma comment thing works. But I dont know why. WHY?

Tanx
U
>>But I dont know why. WHY?

The #pragma directiva makes the linker link with the winsock2 import library - that's the trick.
Avatar of Cryptos

ASKER

aha

tanx