To make all of this work with WinSock you have to make the usual changes.
Replace:
#include <sys/socket.h>
by:
#include <winsock2.h>
You also need to add:
#define _WIN32_WINNT 0x501
#include <ws2tcpip.h>
to the start of the file and add the library files wsock32.a and ws2_32.a which you should find in mingw/lib to the libraries.
As before, the only other changes your program needs to make is to use recv and send in place of read and write and you need to start with a call to WSAStartup to initialize the sockets system:
WSADATA wsaData;
WSAStartup(0x202, &wsaData) ;
where 0x202 specifies that you need at least WinSock 2.2.
Sockets are a general way of making a connection between two programs, perhaps running on different machines.
Sockets are a POSIX standard, but not a C standard. Windows supports a modified form of sockets via WinSock.
To use sockets you have to create a socket, connect it to an address and then transfer data.
Sockets come in two general types – client sockets, which actively connect to another socket and transfer data, and server sockets, which wait for a connection and then service it.
You create a socket using the socket function and you have to specify the type of connection and the detailed protocol in use.
To connect a socket you use the connect function, which accepts a struct which specifies the address of the socket to connect to.
A server socket has to be bound to an address, using the bind function, which it listens on for a client trying to connect.
A server socket also has a listen function, which activates it ready for a client to try to connect. The server then uses the accept function to create a connection.
Once a socket is connected to another socket data can be transferred as if it was a file. It is very easy to create a web client or a web server.
The simplest way to create a server is to use a blocking call to the accept function and leave the thread idle waiting for a client to connect.
A more useful way to handle the connection is in non-blocking mode which allows the thread to do something else while waiting.
IBM is launching a new set of AI software engineering agents designed to autonomously resolve GitHub issues. The agents are being made available in an open-source licensing model.
The offspring of that partnership is pg_duckdb, an extension that embeds the DuckDB engine into the PostgreSQL database, allowing it to handle analytical workloads.