问题描述
- 请帮我看下客户端创建,哪里出现了错误?
-
#include
#include
#include
#include
#pragma comment(lib,"ws2_32.lib")void TCPClient()
{
//创建Socket
SOCKET sockclient = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(INVALID_SOCKET == sockclient)
{
return;
}
//连接到服务器
struct sockaddr_in addr = {0};
addr.sin_family = AF_INET;
addr.sin_port = htons(5678);
addr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
connect(sockclient,(struct sockaddr* )&addr,sizeof(addr));
//数据的收发
getch();
//关闭socket
closesocket(sockclient);
}int main()
{
//Socket库初始化
WSADATA wsa = {0};
WSAStartup(MAKEWORD(2,2),&wsa);
//TCP客户端
TCPClient();return 0;
}
解决方案
参考:http://blog.csdn.net/huangxy10/article/details/8489885
http://blog.csdn.net/weiwangchao_/article/details/6996541
http://binge518.blog.51cto.com/1554719/1222251/
时间: 2024-10-03 00:28:50