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


C++ TCP::closeSocket方法代码示例

本文整理汇总了C++中TCP::closeSocket方法的典型用法代码示例。如果您正苦于以下问题:C++ TCP::closeSocket方法的具体用法?C++ TCP::closeSocket怎么用?C++ TCP::closeSocket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TCP的用法示例。


在下文中一共展示了TCP::closeSocket方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: initTCP

bool initTCP( TCP & tcpConnection, unsigned int & clientSocket )
{
  //initialize TCPIP Connection
  std::cout << "Waiting for TCPIP client..." << std::endl;

  tcpConnection.listenToPort(PORT);
  clientSocket = tcpConnection.acceptConnection();

  if (clientSocket != SOCKET_ERROR)
  {
    std::cout << "Connection accepted" << std::endl;
    return true;
  }

  else
  {
    std::cout << "Failed to accept client" << std::endl;
    tcpConnection.closeSocket(clientSocket);
    return false;
  }
}
开发者ID:ryry0,项目名称:Goliath-Server,代码行数:21,代码来源:main.cpp

示例2: main

//*MAIN*//
int main(int argc, char * argv[])
{
  bool active = true; //flag that controls main loop
  int value;          //value of received message
  char messageType;

  unsigned int  serialPort;

  char * serialAddr = "/dev/ser1";

  TCP tcpConnection;
  unsigned int clientSocket;

  //Initialization
  //Parse the arguments
  switch (argc)
  {
    case 2:
      serialAddr = argv[1];
      break;
  }

  if ( argc >= 2 )
  {
    if ( initSerial(serialPort, serialAddr) == false )
    {
      std::cout << "Serial port initialization failure.\n";
      return 0;
    }
    if ( initMotors() == false )
    {
      std::cout << "Motor initialization failure.\n";
      return 0;
    }
  }

  if ( initTCP(tcpConnection, clientSocket) == false )
  {
    std::cout << "TCPIP initialization failure.\n";
    return 0;
  }

  while (active)
  {
    tcpConnection.receiveData(  clientSocket,
                                (char *) &messageType,
                                sizeof( messageType ));

    if(tcpConnection.receiveData( clientSocket,
                                  (char *) &value,
                                  sizeof( value )) == DATA_ERROR)
    {
      active = false;
      std::cout << "Client Disconnected!" << std::endl;
    }

#ifdef DEBUG
    debugprint(messageType, value);
#endif

    if(messageType == 'X')
      active = false;

    else if (active == true)
    {

#ifdef ENABLE_STEERING
      if (messageType == 'S')
        Move_Motor_Abs(value);
      else
#endif
        motorControl(serialPort, messageType, value);
        //watch out for this!
    }
  }
  std::cout << "Resetting motors..." << std::endl;
  resetMotors(serialPort);

#ifdef ENABLE_STEERING
  Close_Maxon_Motor_Driver();
#endif

  tcpConnection.closeSocket(clientSocket);

  std::cout << "Terminating..." << std::endl;
  return 0;
}
开发者ID:ryry0,项目名称:Goliath-Server,代码行数:88,代码来源:main.cpp


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