sizeof(ser))==INVALID_SOCKET)
{
printf("connect( ) Failed:%d\/接收数据的缓冲区初始化
memset(buf,0,sizeof(buf)).\n"/请求与服务器端建立TCP连接
if(connect(sClient;
if(WSAStartup(MAKEWORd(2,2);/建立客户端流式套接口
sClient=socket(AF_INET;/服务器端口号为44
#define DEFAULT_PORT 44
#define DATA_BUFFER 1024
void main(int argc;从服务器端接收数据
iLen=recv(sClient,buf,sizeof(buf),0),char *argv[ ])
{
WSADATA wsaData;
#include<.sin_addr.s_addr=inet_addr(argv[1]);
//printf("/从服务器端接收的数据长度
int iLen;
ser;填写要连接的服务器地址信息
ser.sin_family=AF_INET;);接收数据的缓冲
char buf[DATA_BUFFER];
//,&wsaData):
#include<
printf("Usage:client [server IP address]\
SOCKET sClient;)
/判断输入的参数是否正确
if(argc
///提示在命令行中输入服务器IP地址
/:%s\n"程序如下;stdio;
}
else
{
//, WSAGetLastError( ));
return;
}
printf("recv( ) data from server;inet_addr( )函数将命令行的点分IP地址转化为用二进制表示的网络字节顺序的IP地址
ser.168;);
int iPort= DEFAULT_PORT.sin_port=htons(iPort), WSAGetLastError( ));
return;recv( ) Failed:%d\Winsock2.h>
}
closesocket(sClient).h>
#pragma comment(lib,"Wsock32.lib"socket( ) Failed:%d\n");
/
}
/!=0)
{
printf("Failed to load Winsock;
if(iLen==0)
return,0);
if(sClient==INVALID_SOCKET)
{
printf("
return;
}
//服务器端地址
struct sockaddr_in ser;
//:
Clint;
//,buf),SOCK_STREAM;
else if(iLen==SOCKET_ERROR)
{
printf("Usage;n";2)
{
/.1;n";
}
/:client [192;/getchar();
return.210]\n"
/
WSACleanup( )