65,211
社区成员
发帖
与我相关
我的任务
分享#ifndef _TCPSERVER_H_
#define _TCPSERVER_H_
#include<netinet/in.h>
#include <sys/select.h>
// write servercongfig.ini
const int SERVPORT = 3333;
const int BACKLOG = 128;
const int TIMEOUT = 5;
const int MAX_DATA_LEN = 1500;
const int RET_OK = 0;
const int RET_ERROR = -1;
const int RET_TIMEOUT = -2;
const int RET_PARAMETER_ERR = -3;
const int SERVER_CONNECT_OK = 0;
const int SERVER_CONNECT_NG = -1;
const int PARSE_DTP_OK = 0;
const int IP_LEN = 16;
typedef struct tagCONNECTSOCKET
{
int iSocket;
char aszClientIP[IP_LEN + 1];
}CONNECTSOCKET;
class CTcpServer
{
public:
TcpServer();
~TcpServer();
void RunServ(void);
static void *RunThread(void);
int SendData(int iSocket, const char *pszData, int iDataLen);
int RecvData(int iSocket, char *pszData, int iDataLen);
private:
bool Init(void);
bool Connect(int *piSockWork, char *pszClientIP, int iLength);
int IsReadyToRead(void);
private:
int m_iServSocket;
struct sockaddr_in m_stuServAddr;
struct timeval m_stuTimeOut;
};
#endif