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