本文整理汇总了C++中TcpServer::init方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpServer::init方法的具体用法?C++ TcpServer::init怎么用?C++ TcpServer::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpServer
的用法示例。
在下文中一共展示了TcpServer::init方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv)
{
// Initialize ROS node "sm_talker"
ros::init(argc, argv, "sm_listener");
// Required to start timers for non-node ROS use.
ros::Time::init();
// Little message to know she's started
ROS_INFO_STREAM("STARTING SM_MANAGER");
// Create and execute manager
// * Create a TCP server connection on TCP_PORT (see common.h)
// * Initialize manager using server connection
// * Initialize handler using server connection
// * Add handler to manager
// * Execute manager spin loop
TcpServer server;
server.init(TCP_PORT);
MessageManager manager;
MyHandler handler;
manager.init(&server);
// Handler initilaized with reply connection (typically the same as
// incoming connection but now always)
handler.init(&server);
manager.add(&handler);
manager.spin();
return 0;
}
示例2: fakeMessagePassing
// Message passing routine, used to send and receive a typed message
// Useful for checking the packing and unpacking of message data.
void fakeMessagePassing(TypedMessage &send, TypedMessage &recv)
{
const int tcpPort = TEST_PORT_BASE+401;
char ipAddr[] = "127.0.0.1";
TcpClient tcpClient;
TcpServer tcpServer;
SimpleMessage msgSend, msgRecv;
send.toTopic(msgSend);
// Construct server
tcpServer.init(tcpPort);
// Construct a client
tcpClient.init(&ipAddr[0], tcpPort);
tcpClient.makeConnect(); // make tcp client connection
tcpServer.makeConnect(); // make tcp server connection
tcpClient.sendMsg(msgSend); // send message
tcpServer.receiveMsg(msgRecv); // physically receive message
recv.init(msgRecv); // copy received message into reference
}
示例3: startTcpServer
void startTcpServer()
{
cout << "TCP Server[" << LOCATION_ADRR << ":" << UDPSERVER_PORT << "] Thread[" <<CurrentThread::info.tid() << "] Start!" << endl;
TcpServer *pTcpServer = new TcpServer();
CHECK_NULLPTR_NORET(pTcpServer);
CHECK_RETURN_VAL_NORET(pTcpServer->init(LOCATION_ADRR, UDPSERVER_PORT));
Uint32 addrLen = 0;
Int32 acceptFd = -1;
struct sockaddr_in clientAddr;
while(1)
{
bzero(&clientAddr, sizeof(clientAddr));
addrLen = sizeof(sockaddr);
acceptFd = pTcpServer->sockAccept((sockaddr*)&clientAddr, &addrLen);
thread t(tcpServerHandle, pTcpServer, inet_ntoa((&clientAddr)->sin_addr), ntohs((&clientAddr)->sin_port), acceptFd);
t.detach();
}
delete pTcpServer;
cout << "TCP Server[" << LOCATION_ADRR << ":" << UDPSERVER_PORT << "] Thread[" <<CurrentThread::info.tid() << "] End!" << endl;
}