Commit 7a48403a authored by Hobnob's avatar Hobnob

it works!

parent 1024f1b7
......@@ -82,45 +82,50 @@ void DoSocket()
WSACleanup();
return;
}
SOCKET ClientSocket = INVALID_SOCKET;
ClientSocket = accept(ListenSocket, NULL, NULL);
if (ClientSocket == INVALID_SOCKET)
SOCKET ClientSocket;
while (true)
{
printf("accept Failed, Error: %d\n", WSAGetLastError());
closesocket(ListenSocket);
WSACleanup();
return;
}
char recvbuf[512];
int iResult, iSendResult;
int recvbuflen = 512;
do {
ClientSocket = INVALID_SOCKET;
ClientSocket = accept(ListenSocket, NULL, NULL);
if (ClientSocket == INVALID_SOCKET)
{
printf("accept Failed, Error: %d\n", WSAGetLastError());
closesocket(ListenSocket);
WSACleanup();
return;
}
char recvbuf[512];
int iResult, iSendResult;
int recvbuflen = 512;
iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
if (iResult > 0) {
printf("Bytes received: %d\n", iResult);
do {
// Echo the buffer back to the sender
iSendResult = send(ClientSocket, recvbuf, iResult, 0);
if (iSendResult == SOCKET_ERROR) {
printf("send failed: %d\n", WSAGetLastError());
iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
if (iResult > 0) {
printf("Bytes received: %d\n", iResult);
std::cout << recvbuf << std::endl;
// Echo the buffer back to the sender
//iSendResult = send(ClientSocket, recvbuf, iResult, 0);
//if (iSendResult == SOCKET_ERROR) {
// printf("send failed: %d\n", WSAGetLastError());
// closesocket(ClientSocket);
// WSACleanup();
// return;
//}
//printf("Bytes sent: %d\n", iSendResult);
}
else if (iResult == 0)
printf("Connection closing...\n");
else {
printf("recv failed: %d\n", WSAGetLastError());
closesocket(ClientSocket);
WSACleanup();
return;
}
printf("Bytes sent: %d\n", iSendResult);
}
else if (iResult == 0)
printf("Connection closing...\n");
else {
printf("recv failed: %d\n", WSAGetLastError());
closesocket(ClientSocket);
WSACleanup();
return;
}
} while (iResult > 0);
} while (iResult > 0);
}
if (shutdown(ClientSocket, SD_SEND) == SOCKET_ERROR)
{
printf("shutdown failed: %d\n", WSAGetLastError());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment