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.45 6.789.000" ;
char* pubcomm::IP_SERVER="123.45 6.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
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.45
char* pubcomm::IP_SERVER="123.45
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
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
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
ASKER
And of course Im using std as namespace...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
you just can't use anything.
apart from that code looks ok.
send us the part you are trying to connect or bind/listen.
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
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.
The #pragma directiva makes the linker link with the winsock2 import library - that's the trick.
ASKER
aha
tanx
tanx
#include <winsock.h>
#include <winsock2.h>
also or
#define INCL_WINSOCK_API_PROTOTYPE
#include <winsock2.h>