1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
// peer 1
char buff[262144]; // 265 kb
LRESULT CALLBACK MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
//...
case WM_SOCKET: // #define WM_SOCKET (WM_USER + 1)
switch (WSAGETSELECTEVENT(lParam))
{
case FD_READ:
{
nBytes += recv(sock, buff, 262144, 0); // always receiving 5840 bytes max
fwrite(buff, 1, 262144, file);
break;
}
//...
}
return 0;
}
// peer2 sends packets from the main loop
while (GetMessage(&msg, nullptr, 0, 0))
{
TanslateMessage(&msg);
DispatchMessage(&msg);
fread(buff, 1, 262144, file);
nBytes += send(sock, buff, 262144, 0);
}
| |