NSUKit 1.4.0
板卡级统一交互接口
载入中...
搜索中...
未找到
nsukit::SocketGenerator类 参考

#include <c_socket.h>

Public 成员函数

 SocketGenerator (unsigned short int port=0, std::string ip="", bool mode=true)
 
 ~SocketGenerator ()
 
void Init (bool update, unsigned short int port=0, std::string ip="")
 
int AcceptClient ()
 
int ConnectServer (float connect_time=SELECT_TIMEOUT)
 
int RecvData (int s, char *buf, int len)
 
int SendData (int s, char *buf, int len)
 
void CloseSock (int s)
 
unsigned short int GetPort () const
 
std::string GetIp ()
 

Public 属性

int recvTimeout
 
int tcpServer {}
 
int tcpClient {}
 
bool tcpClientConnected
 

详细描述

char *data = (char *)"abcd";
unsigned short int port = 5050;
string s_ip("192.168.1.65");
const char *ip = s_ip.c_str();
int mode = 1;
SocketGenerator* s = new SocketGenerator(port, ip, mode);
if (mode) {
cout << s->ConnectServer() << endl;
cout << s->SendData(s->tcpClient, data, 10) << endl;
} else {
while (1) {
int sockConn = s->AcceptClient();
cout << sockConn << endl;
if (sockConn == -1) {
cout << -1 << sockConn << endl;
s->CloseSock(sockConn);
continue;
}
int cmd_id = tcp_recv(*s, sockConn);
if (cmd_id == CMD_ERR) {
break;
} else if (cmd_id == CMD_START) {
// start
} else if (cmd_id == CMD_STOP) {
// stop
}
s->CloseSock(sockConn);
}
}
int SendData(int s, char *buf, int len)
Definition: c_socket.cpp:181
int ConnectServer(float connect_time=SELECT_TIMEOUT)
Definition: c_socket.cpp:99

在文件 c_socket.h70 行定义.

构造及析构函数说明

◆ SocketGenerator()

SocketGenerator::SocketGenerator ( unsigned short int  port = 0,
std::string  ip = "",
bool  mode = true 
)
explicit

在文件 c_socket.cpp7 行定义.

◆ ~SocketGenerator()

SocketGenerator::~SocketGenerator ( )

在文件 c_socket.cpp13 行定义.

成员函数说明

◆ AcceptClient()

int SocketGenerator::AcceptClient ( )

在文件 c_socket.cpp154 行定义.

◆ CloseSock()

void SocketGenerator::CloseSock ( int  s)

在文件 c_socket.cpp192 行定义.

◆ ConnectServer()

int SocketGenerator::ConnectServer ( float  connect_time = SELECT_TIMEOUT)

在文件 c_socket.cpp99 行定义.

◆ GetIp()

std::string nsukit::SocketGenerator::GetIp ( )
inline

在文件 c_socket.h112 行定义.

◆ GetPort()

unsigned short int nsukit::SocketGenerator::GetPort ( ) const
inline

在文件 c_socket.h108 行定义.

◆ Init()

void SocketGenerator::Init ( bool  update,
unsigned short int  port = 0,
std::string  ip = "" 
)

在文件 c_socket.cpp20 行定义.

◆ RecvData()

int SocketGenerator::RecvData ( int  s,
char *  buf,
int  len 
)

在文件 c_socket.cpp170 行定义.

◆ SendData()

int SocketGenerator::SendData ( int  s,
char *  buf,
int  len 
)

在文件 c_socket.cpp181 行定义.

类成员变量说明

◆ recvTimeout

int nsukit::SocketGenerator::recvTimeout

在文件 c_socket.h85 行定义.

◆ tcpClient

int nsukit::SocketGenerator::tcpClient {}

在文件 c_socket.h88 行定义.

◆ tcpClientConnected

bool nsukit::SocketGenerator::tcpClientConnected

在文件 c_socket.h89 行定义.

◆ tcpServer

int nsukit::SocketGenerator::tcpServer {}

在文件 c_socket.h87 行定义.


该类的文档由以下文件生成: