Pages: [1]   Go Down
Author Topic: Ethernet client.read() timeout?  (Read 952 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone, i'm programming a server/client program. My arduino will be server. My question is if there is a time out in client.read?if not how can i make one? my problem is here:

1)client sends 2 bytes
2)server(arduino) reads first, makes some checks to see what was the command
3)and then reads the second byte but sometimes read() returns -1

if i delay() the second read in server no problem!!! i need i time out in read to wait for reading unti a byte come but not forever.
thanks
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If the timeout is not in the read you can build the read in a timeout construct. you need something like:
(not compiled or tested)
Code:
int c;
int cnt = 10;
do
{
c = client.read();
cnt--;
delay(100);  
} while ((-1 == c) && (cnt > 0));

and you could also use client.available() like in - http://arduino.cc/en/Tutorial/WebServer

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: