I'm running a TCP server on my ArduinoYun
if(client){//se è presente un client
Console.println("point1");
while(client.connected()){
Console.println("point2");
if(client.available(){
// char ricevuto = client.read();
// if(ricevuto != '\n'){//se cioè che il client invia non è vuoto
Console.println("point3");
// }
}
}
//client.stop();//fine connessione tcp
}
My client is a mobile phone and the server should just be able to print strings on it. As i try to run it using a TCP port all I get on the serial port is point 1, then the connection stops, which means
while(client.connected())
is where the code stops. How does client.connected() work? Is it a client or a server problem? Let me know if you need more info as I don't really know how to be clear. Thanks.
if(client){//se è presente un client
This code is checking whether the client object exists, it has nothing to do with checking for a successful connection.
It does indeed seem that no connection is actually being made. How are you trying to establish the connection?
Seeing your complete sketch would be very helpful. The problem is either in the part you did not post, or it's in the way you are trying to establish the connection.
I previously posted a working example of a simple TCP connection server IN THIS THREAD
//definizione delle librerie
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
#include "DHT.h"
//definizione di alcune costanti per il sensore e per il server
#define DHTPIN 8
#define DHTTYPE DHT11
#define PORT 1350
//tipo yunserver, specifico della scheda arduino yun
YunServer server(PORT);
//dichiarazione del sensore, tipo dht, caratteristico della libreria dht
DHT dht(DHTPIN, DHTTYPE);
void setup() {
//inizializzazione di Serial, Bridge, Server e Console
Serial.begin(9600);
Bridge.begin();
Console.begin();
server.noListenOnLocalhost();//il server non ascolta sul proprio localhost
server.begin();
}
void loop() {
//metodi per rilevare umidità e temperatura proprio della libreria dht
int h = dht.readHumidity();
int t = dht.readTemperature();
YunClient client = server.accept();//il server è in ascolto accettare la richiesta di SYN da un client
Console.println("tentativo di connessione");
if(client){//se è presente un client
Console.println("client connesso");
while(client.connected()){//mentre la sessione è attiva
Console.println("connessione quasi riuscita");
if(client.available()){//se è il client è ancora disponibile, problema col keepalive della sessione
// char ricevuto = client.read();
// if(ricevuto != '\n'){//se cioè che il client invia non è vuoto
client.println(t);
Console.println("connessione riuscita");
// }
}
}
//client.stop();//fine connessione tcp
}
else{
Console.println("Nessun client connesso, riprova");
}
delay(10000);//ripete ogni 2000ms
}
At this point I guess my problem must be with the client
