Train_RFID_Linux/code/BaseSocket/BaseSocket.h

62 lines
1.0 KiB
C++

//
// Created by matrixai on 3/26/24.
//
#ifndef TRAIN_RFID_LINUX_BASESOCKET_H
#define TRAIN_RFID_LINUX_BASESOCKET_H
#include <string>
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include "AppCommon.h"
#define SOCKET_TIME_OUT_SETTING 10
class BaseSocket
{
public:
BaseSocket();
~BaseSocket();
//打开socket通信
void Open();
//初始化
void Init();
//读取socket数据
int Read();
int Monitor();
//关闭socket通信
void Close();
//设定端口
void SetPort(int port, std::string strIp);
char chbuffer[AEI_COMM_BUFFER_SIZE] = {0};
//是否运行
bool bRuning();
//socket返回值
int nSocketId = 0;
//bind返回值
int nConnectId = 0;
private:
//运行状态
bool bRun = false;
//socket绑定的IP信息
struct sockaddr_in serv_addr;
};
#endif //TRAIN_RFID_LINUX_BASESOCKET_H