二、无连接编程(对等编程UDP)
》》服务器编程
1-UDP套接字创建(socket)
2-地址与端口的绑定(bind)
3-数据的收发(sendto/recvfrom)
4-套接字关闭(close)
》》客户端编程
1-UDP套接字创建(socket)
2-地址与端口的绑定(bind)
3-套接字关闭(close)
server-------------
#include<iostream>
#include<windows.h>
using namespace std;
#pragma comment(lib,"ws2_32.lib")
void main()
{
// WSAStartup//
//该程序功能是让程序能在Windows上面运行,使之和Linux之上运行一样
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
return;
}
/* Confirm that the WinSock DLL supports 2.2.*/
/* Note that if the DLL supports versions greater */
/* than 2.2 in addition