欢迎来到天天文库
浏览记录
ID:41032593
大小:26.00 KB
页数:4页
时间:2019-08-14
《ClientServer socket编程》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、Server/Clientsocket编程//客户端#include#include#include#includeusingnamespacestd;#pragmacomment(lib,"ws2_32.lib")#defineLEN100#defineSERVER_PORT10000intmain(){ WSADATAwsaData; intiResult;chardata[LEN+1];SOCKETsockfd;sockaddr_in
2、saddr; iResult=WSAStartup(MAKEWORD(2,2),&wsaData); if(iResult!=NO_ERROR){cerr<<"WSAStartupfailed:"<3、 WSACleanup(); return1; } saddr.sin_family=AF_INET; saddr.sin_addr.s_addr=inet_addr("127.0.0.1"); saddr.sin_port=htons(SERVER_PORT); iResult=connect(sockfd,(sockaddr*)&saddr,sizeof(saddr));if(iResult==SOCKET_ERROR){ closesocket(sockfd); 4、 cerr<<"Unabletoconnecttoserver:"<5、ckfd); WSACleanup(); return1; }do{memset(data,0,LEN+1);iResult=recv(sockfd,data,LEN,0);if(iResult>0) cout<0);cout<#include<6、memory.h>#include#includeusingnamespacestd;#pragmacomment(lib,"ws2_32.lib")#defineLEN100#defineSERVER_PORT10000intmain(){ WSADATAwsaData; intiResult;chardata[LEN+1]={0};SOCKETsockfd,sockcon;sockaddr_insaddr,sacon;intaddrlen=sizeof(sacon); iRe7、sult=WSAStartup(MAKEWORD(2,2),&wsaData); if(iResult!=NO_ERROR){cerr<<"WSAStartupfailed:"<8、up(); return1; } saddr.sin_addr.S_un.S_addr=htonl(INADDR_ANY); saddr.sin_family=AF_INET; saddr.sin_port=htons(SERVER_
3、 WSACleanup(); return1; } saddr.sin_family=AF_INET; saddr.sin_addr.s_addr=inet_addr("127.0.0.1"); saddr.sin_port=htons(SERVER_PORT); iResult=connect(sockfd,(sockaddr*)&saddr,sizeof(saddr));if(iResult==SOCKET_ERROR){ closesocket(sockfd);
4、 cerr<<"Unabletoconnecttoserver:"<5、ckfd); WSACleanup(); return1; }do{memset(data,0,LEN+1);iResult=recv(sockfd,data,LEN,0);if(iResult>0) cout<0);cout<#include<6、memory.h>#include#includeusingnamespacestd;#pragmacomment(lib,"ws2_32.lib")#defineLEN100#defineSERVER_PORT10000intmain(){ WSADATAwsaData; intiResult;chardata[LEN+1]={0};SOCKETsockfd,sockcon;sockaddr_insaddr,sacon;intaddrlen=sizeof(sacon); iRe7、sult=WSAStartup(MAKEWORD(2,2),&wsaData); if(iResult!=NO_ERROR){cerr<<"WSAStartupfailed:"<8、up(); return1; } saddr.sin_addr.S_un.S_addr=htonl(INADDR_ANY); saddr.sin_family=AF_INET; saddr.sin_port=htons(SERVER_
5、ckfd); WSACleanup(); return1; }do{memset(data,0,LEN+1);iResult=recv(sockfd,data,LEN,0);if(iResult>0) cout<0);cout<#include<
6、memory.h>#include#includeusingnamespacestd;#pragmacomment(lib,"ws2_32.lib")#defineLEN100#defineSERVER_PORT10000intmain(){ WSADATAwsaData; intiResult;chardata[LEN+1]={0};SOCKETsockfd,sockcon;sockaddr_insaddr,sacon;intaddrlen=sizeof(sacon); iRe
7、sult=WSAStartup(MAKEWORD(2,2),&wsaData); if(iResult!=NO_ERROR){cerr<<"WSAStartupfailed:"<8、up(); return1; } saddr.sin_addr.S_un.S_addr=htonl(INADDR_ANY); saddr.sin_family=AF_INET; saddr.sin_port=htons(SERVER_
8、up(); return1; } saddr.sin_addr.S_un.S_addr=htonl(INADDR_ANY); saddr.sin_family=AF_INET; saddr.sin_port=htons(SERVER_
此文档下载收益归作者所有