Category : winsock2

We’ve been debugging an issue where our gRPC connection is getting shutdown (Any ideas why we're getting Intermittent gRPC Unavailable/Unknown RpcExceptions (C++/C#)) and have found that the following call is returning WSAEFAULT: status = WSARecv(tcp->socket->socket, buffers, (DWORD)tcp->read_slices->count, &bytes_read, &flags, &info->overlapped, NULL); Context of the call will be at the bottom of this post. This happens ..

Read more

I have tried to write some code for a proxy with winsock2 in VScode but can’t seem to get it to compile. When i call g++ -std=c++17 -Wall -Wextra -lws2_32 proxy.cpp in the terminal it answers with: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersMARTIN~1AppDataLocalTempccfDVlTW.o:proxy.cpp:(.text+0x5c): undefined reference to `__imp_WSAStartup’ C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersMARTIN~1AppDataLocalTempccfDVlTW.o:proxy.cpp:(.text+0x9a): undefined reference to `__imp_socket’ C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersMARTIN~1AppDataLocalTempccfDVlTW.o:proxy.cpp:(.text+0xd8): undefined reference to `__imp_htons’ ..

Read more

Minimal, reproducable example: #include <cassert> #include <thread> #include <WinSock2.h> #pragma comment(lib, "Ws2_32.lib") constexpr int BUF_SZ = 512; void RecvThread(SOCKET sock) { int iResult = 0; char buf[BUF_SZ] = {}; iResult = recv(sock, buf, BUF_SZ, 0); assert(iResult == SOCKET_ERROR); assert(WSAGetLastError() == WSAESHUTDOWN); } int main() { int iResult; WSADATA wsaData; iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); assert(iResult ..

Read more

#include <sys/types.h> #include <winsock2.h> #include <ws2tcpip.h> #pragma comment(lib, "Ws2_32.lib") #include <stdio.h> #include <stdlib.h> #include <iostream> #include <string> #define WEB_PORT 80 #define BROWSER_PORT 8085 bool is_message(char mess[4096]) { if (mess[55] == ‘G’) return true; return false; } int main() { // initilize WSADATA wsData; WORD ver = MAKEWORD(2, 2); int startup = WSAStartup(ver, &wsData); if (startup ..

Read more