欢迎来到天天文库
浏览记录
ID:39469088
大小:45.50 KB
页数:4页
时间:2019-07-04
《UDP通信服务器和客户端 VC++》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、UDP通信服务器和客户端VC++服务器端://udpserver.cpp:定义控制台应用程序的入口点。//#include"stdafx.h"#include"winsock2.h"#defineBUF_ZIZE64#includeusingnamespacestd;#pragmacomment(lib,"ws2_32.lib")int_tmain(intargc,_TCHAR*argv[]){WSADATAwsd;SOCKETsServer;SOCKETsClient;SOCKADDR
2、_INaddrServ;SOCKADDR_INaddrClient;charbuf[BUF_ZIZE];intretVal;//初始化套接字动态库if(WSAStartup(MAKEWORD(2,2),&wsd)!=0){cout<<"WSAStartuperror"<3、l;WSACleanup();return-1;}//创建客户端套接字sClient=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);if(INVALID_SOCKET==sClient){cout<<"Clientsocketfailed"<4、ily=AF_INET;//绑定套接字retVal=bind(sServer,(LPSOCKADDR)&addrServ,sizeof(SOCKADDR_IN));if(retVal==SOCKET_ERROR){cout<<"binderroe"<5、<6、tem("pause");closesocket(sServer);WSACleanup();return0;}客户端://udpclient.cpp:定义控制台应用程序的入口点。//#include"stdafx.h"#defineBUF_SIZE64#include"winsock2.h"#pragmacomment(lib,"ws2_32.lib")#includeusingnamespacestd;int_tmain(intargc,_TCHAR*argv[]){WSADATAw7、sd;SOCKETsHost;SOCKETsClient;SOCKADDR_INservAddr;charbuf[BUF_SIZE];charcuf[BUF_SIZE];intretVal;//初始化套接字动态库if(WSAStartup(MAKEWORD(2,2),&wsd)!=0){cout<<"WSAStartupfailed"<8、sHost){cout<<"socketfailed"<
3、l;WSACleanup();return-1;}//创建客户端套接字sClient=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);if(INVALID_SOCKET==sClient){cout<<"Clientsocketfailed"<4、ily=AF_INET;//绑定套接字retVal=bind(sServer,(LPSOCKADDR)&addrServ,sizeof(SOCKADDR_IN));if(retVal==SOCKET_ERROR){cout<<"binderroe"<5、<6、tem("pause");closesocket(sServer);WSACleanup();return0;}客户端://udpclient.cpp:定义控制台应用程序的入口点。//#include"stdafx.h"#defineBUF_SIZE64#include"winsock2.h"#pragmacomment(lib,"ws2_32.lib")#includeusingnamespacestd;int_tmain(intargc,_TCHAR*argv[]){WSADATAw7、sd;SOCKETsHost;SOCKETsClient;SOCKADDR_INservAddr;charbuf[BUF_SIZE];charcuf[BUF_SIZE];intretVal;//初始化套接字动态库if(WSAStartup(MAKEWORD(2,2),&wsd)!=0){cout<<"WSAStartupfailed"<8、sHost){cout<<"socketfailed"<
4、ily=AF_INET;//绑定套接字retVal=bind(sServer,(LPSOCKADDR)&addrServ,sizeof(SOCKADDR_IN));if(retVal==SOCKET_ERROR){cout<<"binderroe"<5、<6、tem("pause");closesocket(sServer);WSACleanup();return0;}客户端://udpclient.cpp:定义控制台应用程序的入口点。//#include"stdafx.h"#defineBUF_SIZE64#include"winsock2.h"#pragmacomment(lib,"ws2_32.lib")#includeusingnamespacestd;int_tmain(intargc,_TCHAR*argv[]){WSADATAw7、sd;SOCKETsHost;SOCKETsClient;SOCKADDR_INservAddr;charbuf[BUF_SIZE];charcuf[BUF_SIZE];intretVal;//初始化套接字动态库if(WSAStartup(MAKEWORD(2,2),&wsd)!=0){cout<<"WSAStartupfailed"<8、sHost){cout<<"socketfailed"<
5、<6、tem("pause");closesocket(sServer);WSACleanup();return0;}客户端://udpclient.cpp:定义控制台应用程序的入口点。//#include"stdafx.h"#defineBUF_SIZE64#include"winsock2.h"#pragmacomment(lib,"ws2_32.lib")#includeusingnamespacestd;int_tmain(intargc,_TCHAR*argv[]){WSADATAw7、sd;SOCKETsHost;SOCKETsClient;SOCKADDR_INservAddr;charbuf[BUF_SIZE];charcuf[BUF_SIZE];intretVal;//初始化套接字动态库if(WSAStartup(MAKEWORD(2,2),&wsd)!=0){cout<<"WSAStartupfailed"<8、sHost){cout<<"socketfailed"<
6、tem("pause");closesocket(sServer);WSACleanup();return0;}客户端://udpclient.cpp:定义控制台应用程序的入口点。//#include"stdafx.h"#defineBUF_SIZE64#include"winsock2.h"#pragmacomment(lib,"ws2_32.lib")#includeusingnamespacestd;int_tmain(intargc,_TCHAR*argv[]){WSADATAw
7、sd;SOCKETsHost;SOCKETsClient;SOCKADDR_INservAddr;charbuf[BUF_SIZE];charcuf[BUF_SIZE];intretVal;//初始化套接字动态库if(WSAStartup(MAKEWORD(2,2),&wsd)!=0){cout<<"WSAStartupfailed"<8、sHost){cout<<"socketfailed"<
8、sHost){cout<<"socketfailed"<
此文档下载收益归作者所有