Windows Sockets 2 (Winsock) enables programmers to create advanced Internet, intranet, and other network-capable applications to transmit application data across the wire, independent of the network protocol being used
Questions tagged [winsock2]
964 questions
28
votes
5 answers
Boost::asio winsock and winsock 2 compatibility issue
My project uses windows.h in which winsock.h is used, and I need to include boost:assio which uses winsock2. So I get many errors that says Winsock.h already included.
I can define WIN32_LEAN_AND_MEAN. so that windows.h wouldn't use winsock. The…

Dainius Kreivys
- 525
- 2
- 8
- 19
25
votes
5 answers
undefined reference to `__imp_WSACleanup'
This is my first program with winsock. As you can see, I've #include and linked ws2_32.dll, but the code still doesn't compile:
#include
#pragma comment(lib, "ws2_32")
class CInitSock{
public:
CInitSock(BYTE…

Lance
- 291
- 1
- 3
- 5
20
votes
2 answers
API using sockaddr_storage
I'm trying to do some IP agnostic coding and as suggested by various sources I tried to use sockaddr_storage. However all the API calls (getaddrinfo, getnameinfo) still depend on struct sockaddr. And casting between them isn't exactly a good option,…

Nanda
- 1,038
- 2
- 16
- 33
19
votes
4 answers
TCP Hole Punching
I'm trying to implement TCP hole punching with windows socket using mingw toolchain. I think the process is right but the hole doesn't seems to take. I used this as reference.
A and B connect to the server S
S sends to A, B's router IP + the port…

Giann
- 3,142
- 3
- 23
- 33
19
votes
2 answers
Is it possible to tell if WSAStartup has been called in a process?
I've started writing an ActiveX control that makes use of sockets.
Applications that use this control may or may not also use sockets.
Is it possible for my control to tell whether WSAStartup has been called?
If not, call it. A little test reveals…

hookenz
- 36,432
- 45
- 177
- 286
18
votes
3 answers
WINSOCK - Setting a timeout for a connection attempt on a non existing IP?
I am developing a RTSP Source filter in C++, and I am using WINSOCK 2.0 - blocking socket.
When I create a blocking socket, I set its SO_RCVTIMEO to 3 secs like so:
int ReceiveTimeout = 3000;
int e = setsockopt(Socket, SOL_SOCKET, SO_RCVTIMEO,…

Cipi
- 11,055
- 9
- 47
- 60
18
votes
5 answers
Serialization of struct
Suppose i have a struct whose member values i want to send over the network to another system using winsock 2. I'm using C++ language.
How do i convert it to char * keeping in mind that the struct has to be serialized before sending and also how do…

Vigo
- 707
- 4
- 11
- 29
15
votes
4 answers
Determine between socket and fd
On unix everything is a file approach of function read(), write(), close() is not supported on Win32.
I want to emulate it but have no idea how to distinguish when sock is socket or fd on WinSocks2.
//returns 1 if `sock` is network socket,
// …

DinGODzilla
- 1,611
- 4
- 21
- 34
15
votes
3 answers
Cannot include both files (WinSock2, Windows.h)
I'm having a problem including both files.
Now, I know I need to either include Winsock2 first, then windows.h, or simply put:
#define WIN32_LEAN_AND_MEAN
but, I'm still having problems
I have a header file that is called XS.h which looks like…

Amit
- 683
- 3
- 12
- 25
14
votes
2 answers
Can't include Winsock2.h in MSVC 2010
I cannot include WinSock2.h in a msvc++2010 project. At first I though it was something I was doing wrong, so I created an empty project to test my sanity. The empty project is as follows
#include
#include
int…

john-charles
- 1,417
- 4
- 17
- 30
13
votes
1 answer
Are close() and closesocket() interchangable?
I've seen a lot of answers here that say to use close() to destroy a socket but the guide I used from msdn has me using closesocket(). I'm wondering if there is a difference and if there are reasons to use one or the other.
In both cases, I am…

Enigma
- 1,247
- 3
- 20
- 51
12
votes
2 answers
How to use inet_pton() with the mingw compiler?
I'm trying to add IPv6 compatibility to an already IPv4-compatible program in C, but having some problems with the compiler. Currently compiling with mingw32-gcc-4.6.2, which gives me a linking error when using the function inet_pton.
I've tried…

HNeset
- 125
- 1
- 5
11
votes
3 answers
Windows: Event-based Overlapped IO vs IO Completion Ports, Real World Performance
So I've been looking into overlapped IO for sockets for a server application I'm building, and I keep seeing comments of people saying "never use hEvent" or "IO completion ports will be faster", etc, but no one ever says WHY not to use hEvent and no…

ShadauxCat
- 211
- 2
- 9
9
votes
1 answer
Do I actually have to link Ws2_32.lib?
All Winsock2 examples at MSDN shows that I have to statically link Winsock2 libarary as:
#pragma comment(lib, "ws2_32.lib")
Ensure that the build environment links to the Winsock Library file ?>Ws2_32.lib. Applications that use Winsock must be…

bawytic
- 109
- 1
- 2
- 3
9
votes
4 answers
11001 returned on all calls to getaddrinfo()
Having an issue connecting to a device on my network. Whenever I call getaddrinfo() it returns 11001. I have checked this with numerous different IP's in the IP_ADDRESS string (Global Var). I've checked all the non-working numbers with nslookup, and…

Shocklanced
- 153
- 1
- 1
- 8