18,356
社区成员
发帖
与我相关
我的任务
分享
cIoCP.SendText("0、1、2、3、4、5、6、7、8、9、10、11、12、13、14、15、16、17、18、19\n");
cIoCP.SendText("20、21、22、23、24、25、26、27、28、29、30、31、32、33、34、35、36、37、38、39、40\n");
BOOL ClientIOCP::SendData(char *pData, int nLen)
{
int nBytesSent = 0 ;
//Send the message to the server, include the NULL as well
/*nBytesSent = send(m_socket, pData, nLen, 0);
if (SOCKET_ERROR == nBytesSent)
{
WriteToConsole("\nError occurred while writing to socket %ld.", WSAGetLastError());
return FALSE; //error
}
return TRUE;
*/
ASSERT(NET_DATA_LONGTH> (nLen+3 ) );
//byte 128 WORD longth;
char szBuffer[NET_DATA_LONGTH]={0};
BYTE* lpMask;
lpMask = (BYTE*)(szBuffer);
*lpMask = 128;
WORD* lpLen;
lpLen = (WORD*)(szBuffer+1);
*lpLen = nLen;
memcpy(szBuffer+3 ,pData,nLen );
const int nPernLen = 20;
int nSendLen = 0 ;
int n = 0;
while (nSendLen<nLen)
{
WriteToConsole("%d、发送数据\n",n++);
nBytesSent = send(m_socket, szBuffer+nSendLen, nPernLen, 0);
if (SOCKET_ERROR == nBytesSent)
{
WriteToConsole("\nError occurred while writing to socket %ld.", WSAGetLastError());
return FALSE; //error
}
nSendLen+=nBytesSent;
}
return TRUE;
}
BOOL ClientIOCP::SendText(char *pData)
{
return SendData(pData,strlen(pData)+1);
}