Some problem with use TCP Client because this server response 3 time
i develop api tcp socket on server with node.js this test complete with terminal
for develop on spark core simple code:
void Submit()
{
Serial.println("");
Serial.println("Connecting...");
client.connect(server, 9000);
if (client.connected())
{
Serial.println("Connected to server.");
client.println("Hello, server!");
unsigned int waitCount = 0;
unsigned long lastTime = millis();
// Wait until the server either disconnects, gives us a response, or the timeout is exceeded
Serial.print("Waiting a for response.");
while (client.connected() && !client.available() && millis() - lastTime <
TIMEOUT_INITIAL_RESPONSE)
{
// Visual wait indicator for debugging
if (waitCount++ % 100 == 0)
{
Serial.print(".");
}
// While we are waiting, which could be a while, allow cloud stuff to happen as needed
SPARK_WLAN_Loop();
}
// Show a wait summary for debugging
Serial.println("(wait loops: " + String(waitCount, DEC) + ")");
// We stopped waiting because we actually got something
if (client.connected() && client.available())
{
waitCount = 0;
int charCount = 0;
int lastReadTime = millis();
// Keep going until the server either disconnects, or stops feeding us data in a timely manner
Serial.print("Reading response.");
while (client.connected() && millis() - lastReadTime <
TIMEOUT_RESPONSE_READ)
{
// Visual wait indicator for debugging
if (waitCount++ % 100 == 0)
{
Serial.print(".");
}
// We get something!
while (client.available())
{
char c = client.read();
++charCount;
// Visual data received indicator for debugging
Serial.print("!");
Serial.print(c);
// Make note of when this happened
lastReadTime = millis();
}
}
// Show a wait/read summary for debugging
Serial.println("(wait loops: " + String(waitCount, DEC) +
", chars read: " + String(charCount, DEC) + ")");
}
else
{
Serial.println("No/empty response");
}
// Just to be nice, let's make sure we finish clean
Serial.println("Explicit flush");
client.flush();
Serial.println("Explicit stop");
client.stop();
}
else
{
Serial.println("Connection failed.");
}
delay(RECONNECT_DELAY);
}
This result from serial monitor
Connecting...
Connected to server.
Waiting a for response..(wait loops: 53)
Reading response..!E!c!h!o! !s!e!r!v!e!r!!
!S!y!n!t!a!x! !E!r!r!o!r!!!!!!!!!
!S!y!n!t!a!x! !E!r!r!o!r!!!!!!!!!
!S!y!n!t!a!x! !E!r!r!o!r!!!!!!!!!
..........(wait loops: 1005, chars read: 64)
Explicit flush
Explicit stop
Connect
why response 3 time on ( !S!y!n!t!a!x! !E!r!r!o!r!!! )
How to fix it !!!
Thx ^ ^