ipv6实现tcp编程示例
本文导语: 开发测试环境:WIN7SP、 VS2005 TcpServer.cpp 代码如下:#include #include #include #pragma comment(lib, "ws2_32.lib") int main(int argc, char** argv){ using namespace std; coutai_addr, res->ai_addrlen); if (0 != listen(sk, 5)) { WSACleanup(); closesocket(sk); return -1; ...
开发测试环境:WIN7SP、 VS2005
TcpServer.cpp
#include
#include
#include
#pragma comment(lib, "ws2_32.lib")
int main(int argc, char** argv)
{
using namespace std;
coutai_addr, res->ai_addrlen);
if (0 != listen(sk, 5))
{
WSACleanup();
closesocket(sk);
return -1;
}
struct sockaddr_storage storage;
int len = sizeof(storage);
memset(&storage, 0, len);
SOCKET newSk = accept(sk, (struct sockaddr*)&storage, &len);
closesocket(sk);
char recvBuf[1024] = {''};
int lenRecv = 0;
lenRecv = recv(newSk, recvBuf, 1024, 0);
cout