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
6
votes
0 answers
Is it necessary to call WSACleanup before program exit
I have a Windows socket program (XP and above) that calls WSAStartup. Is it necessary to call WSACleanup before the program exits? If I don't, will there be any negative consequences? In particular is:
WSACleanup();
exit(0);
different from merely…

Neil Mitchell
- 9,090
- 1
- 27
- 85
6
votes
2 answers
Why socket descriptors on Windows get such values?
Not sure if it's the right place to ask, anyway.
I'm writing a simple chat with c++, where a client gets socket value as nickname for beginning.
On linux sockets are just file descriptors and they get their 3, 4, 5... that follow stdin, stdout,…

Aenry
- 117
- 1
- 9
6
votes
3 answers
Implicit declaration of function 'getaddrinfo' on MinGW
I have a C program that uses getaddrinfo(). It works as expected on Linux and Mac OS X.
I'm in the middle of porting it to Windows.
When I compile it (with MinGW gcc) I get the following warnings:
ext/socket/socket.c: In function…
user47322
5
votes
4 answers
socket() return -1 but errno 0
I tried to create a UDP socket on mingw, but socket() returns -1, with errno = 0. Strange.
I have included winsock2.h.
Initially I had compilation error undefined reference to socket@12, after setting
-lws2_32 and -lwsock32 to Linker Settings of…

twfx
- 1,664
- 9
- 29
- 56
5
votes
2 answers
C Sockets: Avoiding garbage when socket is closed
I'm programming a server and a client using non blocking sockets (fd_sets and select function) and once the server closes or shuts down a client socket, the client starts receiving a lot of garbage until it crashes..
I've been warned that when…

Lucas
- 77
- 6
5
votes
4 answers
Redirect IO of process to Windows socket
I am new to winsock, I tried to write a server socket that accepts new connection, then it calls an external executable file. How can we redirect the stdin and stdout of the external executable file to the client socket which has been accepted. I…

Dien Nguyen
- 2,019
- 6
- 30
- 37
5
votes
1 answer
IO Completion Port Initial Read and Bi-Directional Data
I have the following simplified IO Completion Port server C++ code:
int main(..)
{
startCompletionPortThreadProc();
// Await client connection
sockaddr_in clientAddress;
int clientAddressSize = sizeof( clientAddress );
SOCKET…

Brent Campbell
- 395
- 1
- 4
- 12
5
votes
3 answers
How does Winsock2 listen() blocks?
MSDN says that : Listen() is a blocking call. Code snippet from a function in which i have used listen() is shown below:
sockaddr_in addr = {0};
int addrlen = sizeof(addr);
SOCKET sock_listen;
if(-1 == (sock_listen = socket(AF_INET,…

Aravind
- 555
- 1
- 3
- 12
5
votes
2 answers
How to use getaddrinfo()?
Im trying to make a simple program that takes in a string like www.google.com and returns the ip address...
What i have so far:
char* hostname = new char[www.size()+1];
std::copy(www.begin(), www.end(), hostname);
hostname[www.size()] =…

Kelvin
- 233
- 1
- 4
- 13
5
votes
2 answers
is winsock2 thread safe?
I am writing a small 3 servers and 1 client program. the 2 servers send tcp messages and the last one sends upd datagrams using winsock2.
I am wondering if i can make simulanious recvfrom() by using threads (OpenMP or boost::threads) so that 2…

ezzakrem
- 399
- 5
- 15
5
votes
1 answer
When using IOCP, should I set WSAOVERLAPPED's hEvent to NULL or to a valid handle to a WSAEVENT object?
According to MSDN:
hEvent: If an overlapped I/O operation is issued without an I/O
completion routine (the operation's lpCompletionRoutine parameter is
set to null), then this parameter should either contain a valid handle
to a WSAEVENT…

jpen
- 2,129
- 5
- 32
- 56
5
votes
2 answers
Winsock2 - How to use IOCP on client side
I’ve recently started learning IOCP on Windows and been reading the following article:
http://www.codeproject.com/Tips/95363/Another-TCP-echo-server-using-IOCP
You can download the sample for the article…

jpen
- 2,129
- 5
- 32
- 56
4
votes
2 answers
Winsock2, client-server communication - send/recv in turns
I want to write a client/server application, in which client and server can exchange messages.
Client site communication:
send
recv
send
recv
Server site communication:
recv
send
recv
send
However, I have a problem, because only one message is…

yak
- 3,770
- 19
- 60
- 111
4
votes
2 answers
Sending data from Java to C using socket programming
i am making a program that sends a string from a Java client to a C server using WinSock2. I am using DataOutputStream to send the data through the socket.
The C server, acknowledges the bytes received, but when i try accessing the data, nothing is…

user761968
- 41
- 1
- 2
4
votes
0 answers
Socket IO control in .NET Core for DSCP
.NET Core provides Sockets class which is an implementation of Berkely Sockets API.
It provides a method IOControl that allows setting low-level IO Control. It also has an enum where we can use IOControlCode.SetQos. What should be the value of…

Jigar
- 544
- 1
- 8
- 28