问题描述
- C++socket数据接收处理问题
-
1.能够点了按钮之后能够一直接收发送过来的单行数据
2.能把接收的数据处理好了之后存到另外定义的数组或list中去
3.那个线程应该如何定义程序才能执行
SOCKET sHost;
WSADATA wsd;
SOCKET sServer;
SOCKET sClient;
SOCKADDR_IN addrServ;
void CMyDlg::OnRev()
{
#define BUF_SZIE 64
#pragma comment(lib, "ws2_32.lib")
char buf[BUF_SZIE];
int retVal;
if (WSAStartup(MAKEWORD(2,2), &wsd) != 0)
{
printf("WSAStartup failed!n");
}
sServer = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);addrServ.sin_family = AF_INET;
addrServ.sin_port = htons(3000);
addrServ.sin_addr.s_addr = INADDR_ANY;retVal = bind(sServer, (LPSOCKADDR)&addrServ, sizeof(SOCKADDR_IN));
retVal = listen(sServer, 10);sockaddr_in addrClient;
int addrClientlen = sizeof(addrClient);
sClient = accept(sServer,(sockaddr FAR*)&addrClient, &addrClientlen);
?
ZeroMemory(buf, BUF_SZIE);
while(true)
{
retVal = recv(sClient, buf, BUF_SZIE, 0);
if (SOCKET_ERROR == retVal)
{
printf("send failed!n");
}
else
{
......
}
}
closesocket(sClient);
WSACleanup();
}求大神指点一二
- List item
时间: 2024-11-03 11:33:09