Blue_Nile
2015-03-10 06:40
采纳率: 85.7%
浏览 1.8k
已采纳

请帮我看下客户端创建,哪里出现了错误?

#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;

}


  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题