5 #include "../skelserver/skelserver.h"
7 DWORD WINAPI
EchoHandler(VOID
* Sock_
)
10 SOCKET Sock
= (SOCKET
)Sock_
;
12 if (!EchoIncomingPackets(Sock
)) {
13 _tprintf(_T("Echo incoming packets failed\n"));
17 _tprintf(_T("Shutting connection down...\n"));
18 if (ShutdownConnection(Sock
)) {
19 _tprintf(_T("Connection is down.\n"));
23 _tprintf(_T("Connection shutdown failed\n"));
32 BOOL
EchoIncomingPackets(SOCKET Sock
)
34 TCHAR ReadBuffer
[BUF
];
40 ReadBytes
= recv(Sock
, ReadBuffer
, BUF
, 0);
42 _tprintf(_T("Received %d bytes from client\n"), ReadBytes
);
45 while (SentBytes
< ReadBytes
) {
46 Temp
= send(Sock
, ReadBuffer
+ SentBytes
,
47 ReadBytes
- SentBytes
, 0);
49 _tprintf(_T("Sent %d bytes back to client\n"), Temp
);
52 else if (Temp
== SOCKET_ERROR
) {
56 /* Client closed connection before we could reply to
57 all the data it sent, so quit early. */
58 _tprintf(_T("Peer unexpectedly dropped connection!\n"));
63 else if (ReadBytes
== SOCKET_ERROR
) {
66 } while (ReadBytes
!= 0);
68 _tprintf(("Connection closed by peer.\n"));