Visual C++网络编程学习(1)-UDP阻塞模型
利用C++搭建了一个简单的UDP阻塞模型,只是做了客户端的发送与服务器的接收。程序我已经测试了一遍,如果大家在看的过程中有什么问题,也希望大家相互交流。代码如下:
服务器代码:
#include<iostream>
#include<WINSOCK2.h>
#pragma comment(lib,"Ws2_32.lib")
using namespace std;
#define SERVEPORT 10000
#define CLIENTPORT 100
class CUdpConnectServe
{
public:
CUdpConnectServe()
{};
~CUdpConnectServe()
{};
//socket函数
int InitSocketConnect(); //初始化SOCKET
void CloseSocketConnect(); //关闭SOCKET
int Receive(
_Out_writes_bytes_to_(len, return) __out_data_source(NETWORK) char FAR * buf,
_In_ int len,
_In_ int flags
);
//客户端地址
sockaddr_in m_soClientAddr;
private:
SOCKET m_SocketServe;
sockaddr_in m_soServeAddr;
SOCKET m_SocketClient;
int m_nAddrlen;
};
//初始化SOCKET
int CUdpConnectS