1 构造函数
创建一个未连接的 IPv4 数据报 Socket:
DatagramSocket();
创建一个指定 IP 类型(IPv4 或 IPv6)的数据报 Socket:
explicit DatagramSocket(IPAddress::Family family);
创建一个指定 SocketAddress 的数据报 Socket
DatagramSocket(const SocketAddress& address, bool reuseAddress = false);
DatagramSocket(const Socket& socket);
/// Creates the DatagramSocket with the SocketImpl
/// from another socket. The SocketImpl must be
/// a DatagramSocketImpl, otherwise an InvalidArgumentException
/// will be thrown.
2 重载运算符
DatagramSocket& operator = (const Socket& socket);
/// Assignment operator.
///
/// Releases the socket's SocketImpl and
/// attaches the SocketImpl from the other socket and
/// increments the reference count of the SocketImpl.
3 常用操作
3.1 连接与绑定
void connect(const SocketAddress& address);
void bind(const SocketAddress& address, bool reuseAddress = false);
3.2 收发数据且不考虑 client
int sendBytes(const void* buffer, int length, int flags = 0);
int receiveBytes(void* buffer, int length, int flags = 0);
3.3 手法数据且获取 client 的 SocketAddress
int sendTo(const void* buffer, int length, const SocketAddress& address, int flags = 0);
int receiveFrom(void* buffer, int length, SocketAddress& address, int flags = 0);
3.4 收发广播
void setBroadcast(bool flag);
bool getBroadcast() const;
4 protected 函数
DatagramSocket(SocketImpl* pImpl);
-
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2013-09-29 C/C++代码静态检查工具Cppcheck在VS2008开发环境中的安装配置和使用
2013-09-29 MFC上下浮动与渐入渐出消息提示框实现
2013-09-29 MFC渐入渐出框实现方式二
2013-09-29 Cppcheck软件使用