I'm having a hard time implementing the client to connect with the IOCP server in an asynchronous manner. Sending packets from the client to the server using WSASend worked normally.
Connection and Packet send Code - Client
SOCKADDR_IN svr_addr;
memset(&svr_addr, 0, sizeof(svr_addr));
svr_addr.sin_family = AF_INET;
svr_addr.sin_port = htons(SERVER_PORT);
inet_pton(AF_INET, SERVER_IP, &svr_addr.sin_addr);
ErrorStatus = WSAConnect(s_socket, reinterpret_cast<sockaddr*>(&svr_addr), sizeof(svr_addr), 0, 0, 0, 0);
if (ErrorStatus == SOCKET_ERROR) err_display(WSAGetLastError());
CS_LOGIN_PACKET p;
p.size = sizeof(CS_LOGIN_PACKET);
p.type = CS_LOGIN;
s_wsabuf->len = p.size;
s_wsabuf->buf = reinterpret_cast<char*>(&p);
ZeroMemory(&s_over, sizeof(s_over));
ErrorStatus = WSASend(s_socket, s_wsabuf, 1, 0, 0, &s_over, 0);
if (ErrorStatus == SOCKET_ERROR) err_display(WSAGetLastError());
Packet receive code - Client
s_wsabuf[0].buf = s_buf;
s_wsabuf[0].len = BUF_SIZE;
DWORD r_flag = 0;
DWORD r_bytes = 0;
memset(&s_over, 0, sizeof(s_over));
int ret = WSARecv(s_socket, s_wsabuf, 1, &r_bytes, &r_flag, &s_over, recv_callback); // - recv_callback function is not working
if (ret == SOCKET_ERROR && WSAGetLastError() != WSA_IO_PENDING) // WSAGetLastError returns WSA_IO_PENDING.
err_display("WSARecv()");
Packet send code - Server
// OVER_EXP is a class that contains WSABUF and WSAOVERLAPPED as member variables.
OVER_EXP* sdata = new OVER_EXP{ reinterpret_cast<char*>(packet) };
int ret = WSASend(_socket, &sdata->_wsabuf, 1, 0, 0, &sdata->_over, 0);
Both the server and client sockets were made overlapped using WSASocket (AF_INET, SOCK_STREAM, 0, NULL, 0, WSA_FLAG_OVERLAPPED); functions.
As a result of checking the return value of the WSASend() function of the server and the lpNumberOfBytesSent value, send worked normally. What prevents WSARecv() from running the callback function? I am sorry that the question is not clear and simple due to my poor knowledge.