1
我的應用程序中發現我收到的字節數超過了我的預期。我不知道這2個字節意味着什麼,因爲在客戶機中我記錄了發送的字節,並且我收到了服務器上的所有數據,但是在數據發送之後,我仍然收到了這兩個字節導致程序崩潰。爲什麼?任何想法?發送的字節數多於我應該通過套接字接收到的字節數
客戶端
int sentBytes = send(socket, data, size, 0);
上和
int receivedBytes = SOCKET_ERROR;
char *header = new char[8];
receivedBytes = recv(socket, header, 8, 0);
if (receivedBytes == 0 || receivedBytes == WSAECONNRESET)
{
...
}
else
{
size_t data_size = 0;
std::istringstream is(std::string(header, 8));
if (!(is >> std::hex >> data_size))
{
char *data = new char[data_size + 1];
data_size = recv(socket, data, data_size, 0);
}
}
我使用的win32消息循環與WSAAsyncSelect
EDIT 2在服務器上EDIT 1
我使用的是前8個字節發送包含該消息的長度,我應該接受在服務器上的十六進制值
發表一些代碼,我失去了我的水晶球。 – 2011-04-28 16:56:53
開始和結束傳輸(STX和ETX)字符被佔? – 2011-04-28 17:02:22
@Heandel @Cole對不起,我不明白,你在說什麼? – Stefano 2011-04-28 17:03:11