C++ implements socket IOCP

In the past few days, I have been studying multi-threading and network socket models. I wrote these and recorded them based on Teacher Renzhai’s C++ tutorial and the API reference provided by Windows as well as some information on the Internet. Server side code. #define _CRT_SECURE_NO_WARNINGS #include <WinSock2.h> #include <list> #include <process.h> #include <iostream> #pragma […]

Windows C++ uses IOCP IO multiplexing to simultaneously monitor 1000 tcp socket messages

Windows C++ uses IOCP IO multiplexing to simultaneously monitor 1000 tcp socket messages Establish a TCP connection BOOL CreateConnection(SOCKET socket, CString strServerIP, const CString strServerPort) {<!– –> // create socket socket = socket(AF_INET, SOCK_STREAM, 0); if(socket == INVALID_SOCKET) {<!– –> WriteError(_T(“socket() called failed!”)); return -1; } unsigned long ul = 1; \t // Set socket […]

Windows socket I/0 model – IOCP completion port model

In Windows network programming, IOCP (Input/Output Completion Port) is a high-performance I/O model that enables applications to handle a large number of concurrent I/O operations. The IOCP model mainly handles asynchronous I/O operations through event notification and callback functions. Compared with the previously introduced models such as select, WSAAsyncSelect and WSAEventSelect, the advantage of the […]

IOCP model under windows

1 iocp echo server ————————————-ThreadPool.h——- ——————————— //The thread pool is the basis of the iocp echo server #pragma once #include <atomic> #include <process.h> #include <vector> #include <mutex> #include <WinSock2.h> #include <atlstr.h> #include <iostream> typedef int (*FUNCTYPE)(void*); class ThreadWorker { public: ThreadWorker() : func(NULL), arg(arg) {}; ThreadWorker(FUNCTYPE f, void* arg = NULL) : func(f), arg(arg) {} […]