📄 mysocket.h
字号:
//MySocket.h#ifndef MySocket_h#define MySocket_h#include <sys/socket.h>#include <arpa/inet.h>#include <string>//==================== MyConnect ====================class MyConnect{public : MyConnect() ; ~MyConnect() ; bool open(int domain = AF_INET , int type = SOCK_STREAM , int protocol = 0) ; bool connect(const char *server = "" , int port = 2404 , int domain = AF_INET) ; operator int() const ; private : bool shutdown(int how = 2) const ; private : int m_socket ;} ;//==================== MyListen ====================class MyListen{public : MyListen(int domain = AF_INET , int type = SOCK_STREAM , int protocol = 0) ; ~MyListen() ; bool shutdown(int socket , int how = 2) const ; bool bind(const char *server , int port = 2404 , int domain = AF_INET) ; //IP Address , Only Use , Not Delete bool listen(int backlog = 5) const ; int accept(std::string &ip) ; //IP Address , Only Use , Not Delete , Teturn New Socket To Communicate private : MyListen(const MyListen &) ; //Not Define To Prevent Be Called MyListen & operator =(const MyListen &) ; //Not Define To Prevent Be Called private : int m_socket ; sockaddr_in m_server ; sockaddr_in m_client ;} ;//==================== MySocket ====================class MySocket{public : MySocket() ; ~MySocket() ; bool needReset() const ; MySocket & operator =(const MyConnect &connect) ; MySocket & operator =(int socket) ; int receive(void *buf , int len , int time_out = 5 , unsigned int flags = 0) ; //Receive 3 Times , Only Use , Not Delete , -1 For Error int send(const void *msg , int len , unsigned int flags = 0) ; //Only Use , Not Delete , -1 For Error private : bool shutdown(int how = 2) ; MySocket(const MySocket &) ; private : int m_socket ; bool m_reset ;} ;#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -