当前位置: 首页>>代码示例>>C++>>正文


C++ TcpServer::init方法代码示例

本文整理汇总了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;
}
开发者ID:drchrislewis,项目名称:industrial_training,代码行数:33,代码来源:sm_manager.cpp

示例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
}
开发者ID:usnistgov,项目名称:el-robotics-core,代码行数:27,代码来源:rosthread.cpp

示例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;
}
开发者ID:weijian2014,项目名称:baselib,代码行数:23,代码来源:tcpSocketTest.cpp


注:本文中的TcpServer::init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。