本文整理汇总了C++中TcpServer::acceptClient方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpServer::acceptClient方法的具体用法?C++ TcpServer::acceptClient怎么用?C++ TcpServer::acceptClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpServer
的用法示例。
在下文中一共展示了TcpServer::acceptClient方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WiFiCmdRobot_main
int WiFiCmdRobot::WiFiCmdRobot_main() {
String stringRead;
int conx = 0;
unsigned long timeout = 5; // 5s
unsigned long start = 0;
int ret=SUCCESS;
// not specifically needed, we could go right to AVAILABLECLIENT
// but this is a nice way to print to the serial monitor that we are
// actively listening.
// Remember, this can have non-fatal falures, so check the status
while (1) {
if(tcpServer.isListening(&status))
{
Serial.print("Listening on port: ");
Serial.println(portServer, DEC);
digitalWrite(Led_Yellow, HIGH); // turn on led yellow
break;
}
else if(DNETcK::isStatusAnError(status))
{
Serial.println("Error Listening");
tcpClient.close();
tcpServer.close();
return -1;
}
}
// wait for a connection until timeout
conx = 0;
start = millis();
while ((millis() - start < timeout*1000) && (conx == 0)) {
if((count = tcpServer.availableClients()) > 0)
{
Serial.print("Got ");
Serial.print(count, DEC);
Serial.println(" clients pending");
conx = 1;
// probably unneeded, but just to make sure we have
// tcpClient in the "just constructed" state
tcpClient.close();
}
}
// accept the client
if((conx == 1) && (tcpServer.acceptClient(&tcpClient)))
{
Serial.println("Got a Connection");
lcd.clear();
lcd.print("Got a Connection");
stringRead = "";
while (tcpClient.isConnected())
{
if (tcpClient.available())
{
char c = tcpClient.readByte();
if (c == '\n')
{
Serial.println (stringRead);
if (stringRead.startsWith("GET"))
{
Serial.println("GET");
ret = Cmd (stringRead);
if (ret == SUCCESS)
{
ret = ReplyOK ();
}
else
{
cmd_GO[0] = 0; //reset GO command
ret = ReplyKO ();
}
break;
}
else if (stringRead.startsWith("\r"))
{
// empty line => end
Serial.println("empty line => end");
break;
}
else
{
// no GET
Serial.println("no GET => ignore");
}
stringRead = "";
}
else
{
stringRead += c;
}
}
} // end while
}
else if((cmd_GO[0] == CMD_GO) && (cmd_GO[1] > t_GO+(uint16_t)timeout)) // GO ongoing
{
Serial.println("Continue command GO");
//.........这里部分代码省略.........