本文整理汇总了C++中TCP::receiveData方法的典型用法代码示例。如果您正苦于以下问题:C++ TCP::receiveData方法的具体用法?C++ TCP::receiveData怎么用?C++ TCP::receiveData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TCP
的用法示例。
在下文中一共展示了TCP::receiveData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}