is winsock2 thread safe?

Yes, sockets are thread-safe, however you have to be careful. One common pattern (when using blocking IO) is to have one thread receiving data on a socket and another thread sending data on the same socket. Having multiple threads receiving data from a socket is usually fine for UDP socket, but doesn’t make much sense … Read more

Serialization of struct

Following example shows a simplest way to serialize struct into char array and de-serialize it. #include <iostream> #include <cstring> #define BUFSIZE 512 #define PACKETSIZE sizeof(MSG) using namespace std; typedef struct MSG { int type; int priority; int sender; char message[BUFSIZE]; }MSG; void serialize(MSG* msgPacket, char *data); void deserialize(char *data, MSG* msgPacket); void printMsg(MSG* msgPacket); int … Read more