?
Solved

Problems with winsock2.h

Posted on 2003-03-05
8
Medium Priority
?
406 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

764 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