socket.h
来自「Linux下telnet客户端的C++代码实现。用于初学者对telnet协议的学」· C头文件 代码 · 共 55 行
H
55 行
// Definition of the Socket class#ifndef Socket_class#define Socket_class#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <netdb.h>#include <unistd.h>#include <string>#include <arpa/inet.h>const int MAXHOSTNAME = 200;const int MAXCONNECTIONS = 5;const int MAXRECV = 500;class Socket{ public: Socket(); virtual ~Socket(); // Server initialization bool create(); bool bind ( const int port ); bool listen() const; bool accept ( Socket& ) const; // Client initialization bool connect ( const std::string host, const int port ); // Data Transimission bool send ( const std::string ) const; int send(const void *buf, size_t len) const; int recv ( std::string& ) const; int recv ( char *sBuf ) const; void set_non_blocking ( const bool ); bool is_non_blocking ( void ); bool is_valid() const { return m_sock != -1; } private: int m_sock; sockaddr_in m_addr;};#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?