PageDNS

PageDNS

vps爱好者乐园

Windows Socket 编程:TCP客户端

#include <stdio.h>

#include <stdlib.h>

#include <winsock2.h>


int main(int argc,char * argv[])

{

char message[30];

WSADATA wsaData;

SOCKET hSocket;

SOCKADDR_IN servAddr;


WSAStartup(MAKEWORD(2,2),&wsaData);

hSocket = socket(PF_INET,SOCK_STREAM,0);


memset(&servAddr,0,sizeof(servAddr));

servAddr.sin_family = AF_INET;

servAddr.sin_addr.s_addr = inet_addr(argv[1]);

servAddr.sin_port = htons(atoi(argv[2]));


connect(hSocket,(SOCKADDR *)&servAddr,sizeof(servAddr));


recv(hSocket,message,sizeof(message) - 1,0);

printf("%s",message);


closesocket(hSocket);

WSACleanup();


return 0;

}


上一篇:华为存储服务器卷丢失数据恢复成功案例

下一篇:没有了