?
Solved

Problems with winsock2.h

Posted on 2003-03-05
8
Medium Priority
?
408 Views
Last Modified: 2008-02-07
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
0
Comment
Question by:Cryptos
  • 4
  • 3
8 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 8071899
You have to either

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

also or

#define INCL_WINSOCK_API_PROTOTYPES
#include <winsock2.h>
0
 

Author Comment

by:Cryptos
ID: 8072019
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
0
 

Author Comment

by:Cryptos
ID: 8072034
And of course Im using std as namespace...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Accepted Solution

by:
jkr earned 400 total points
ID: 8072087
>>It seems to be a linking problem...

You mean you get linker errors? If so, add ws2_32.lib to your project, e.g.

#include <winsock2.h>
#pragma comment ( lib, "ws2_32.lib")

0
 
LVL 1

Expert Comment

by:codez80
ID: 8074939
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.

0
 

Author Comment

by:Cryptos
ID: 8075118
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
0
 
LVL 86

Expert Comment

by:jkr
ID: 8075148
>>But I dont know why. WHY?

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

Author Comment

by:Cryptos
ID: 8075185
aha

tanx
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question