【RLIB】Socket类 的C++简易实现
来源:互联网 发布:科幻悬疑 知乎 编辑:程序博客网 时间:2024/04/26 00:34
相关源码参见RLIB开源项目
下面是RLIB1.x的头文件:
namespace System{namespace Net{/// <summary>/// 提供对Winsock的标准访问/// </summary>class export Sockets{protected:SOCKET m_socket;sockaddr_in m_addr;Exception *m_error;public:Sockets(SOCKET s = INVALID_SOCKET);~Sockets();RLIB_ClassNewDel;public:/// <summary>/// 方法允许您获取SOCKET以便进行更多的操作/// 您亦可继承并拓展Sockets类的功能/// </summary>operator SOCKET();/// <summary>/// 设置发送超时/// </summary>bool SetSndTimeO(int timeout);/// <summary>/// 获取发送缓冲区/// </summary>int GetSndBuf();/// <summary>/// 设置接收超时/// </summary>bool SetRcvTimeO(int timeout);/// <summary>/// 获取接收缓冲区/// </summary>int GetRcvBuf();/// <summary>/// Closes an existing socket/// </summary>bool Close();/// <summary>/// Establishes a connection to a specified socket/// </summary>bool Connect(char *host, unsigned int host_len, u_short port);/// <summary>/// Sends data on a connected socket/// 当发生错误时,size用来接收已发送长度/// </summary>bool Send(char *data, int *size);/// <summary>/// Receives data from a connected or bound socket/// 当发生错误时,size用来接收已接收长度/// </summary>int RecvEx(char *buf, int *size); /// <summary>/// Receives data from a connected or bound socket/// 该方法不保证收完指定 size/// </summary>int Recv(char *buf, int size); /// <summary>/// associates a local address with a socket/// </summary>int Bind(ULONG addr, u_short port); /// <summary>/// associates a local address with a socket/// 方法绑定到所有地址上/// </summary>int Bind(u_short port); /// <summary>/// Places a socket a state where it is listening for an incoming connection/// </summary>int Listen(int backlog = SOMAXCONN); /// <summary>/// Permits an incoming connection attempt on a socket/// An optional pointer to a buffer that receives the address of the connecting entity,/// as known to the communications layer./// </summary>Sockets *Accept(sockaddr_in *addr = NULL, int *addrlen = NULL); /// <summary>/// Disables sends or receives on a socket/// </summary>int Shutdown(int how = SD_BOTH);/// <summary>/// 获取Wincock发生的异常信息/// 该方法仅提供于实例对象/// </summary>Exception *GetLastException(); /// <summary>/// 获取一个值,该值指示是否与 Internet 已建立连接/// </summary>bool IsConnect; public:/// <summary>/// 获取本地计算机名称/// </summary>static bool GetLocalHost(char *host, int hostlen);/// <summary>/// 获取本地计算机地址/// </summary>static bool GetLocalIpAddress(char *host, PADDRINFOA *addrinfo);/// <summary>/// 释放由GetLocalIpAddress获得的addrinfo/// </summary>static void FreeLocalIpAddress(PADDRINFOA *addrinfo);/// <summary>/// Converts a string containing an (Ipv4) Internet Protocol dotted address into a proper address for the in_addr structure/// </summary>static unsigned long Ipv4StringToAddress(const char *cp);/// <summary>/// Converts an (IPv4) Internet network address into a string in Internet standard dotted format/// </summary>static char *Ipv4AddressToString(in_addr in);/// <summary>/// 获取Wincock发生的错误说明/// </summary>static bool GetLastError(LPVOID buffer, size_t size, int err = 0);/// <summary>/// 当不再使用Winsock的时候调用此方法会释放网络模块内存/// </summary>static void Dispose();};}}
- 【RLIB】Socket类 的C++简易实现
- 【RLIB】String 的简易C++实现
- 【RLIB】线程安全内存池(Memory) 的简易C++实现
- 【RLIB】内存流(Stream) 的简易C++实现
- 基于Linux c 用socket和线程 实现的简易聊天室之服务器
- 基于Linux C 用socket和线程 实现的简易聊天室之客户端
- socket实现简易聊天工具
- Socket编程实现简易聊天室
- C#delegate的C++简易实现
- 利用c实现简易的ping
- c语言实现的简易窗口程序
- c语言简易五子棋的实现
- 【C++】C++简易实现C#的delegate
- C语言实现简易的信贷系统
- 数据结构-图的简易实现-C
- 利用socket网络编程,实现的简易CS计算器
- 【android】android socket 实现简易的聊天室功能
- JAVA使用Socket实现的简易HTTP服务器
- 匈牙利命名规则
- Java Foundation Classes Hierarchy
- Ruby:用block简化编程一例
- MPI编程
- jquery 特效整合
- 【RLIB】Socket类 的C++简易实现
- 感冒
- framework---bt
- 常用的Intent Flag 说明
- 使用Python实现win32下IconOverlay开发
- http://www.cnblogs.com/iminto/archive/2010/12/23/1915232.html
- 500 OOPS: vsftpd: refusing to run with writable anonymous root
- SSH(Struts,Spring,Hibernate)的面试题
- 2012-02-02