Hi to all,
I have a doubt about running a "web server" process on Arduino.
I read that with this line code Arduino is listening for incoming clients.
// listen for incoming clients
Client client = server.available();
What happen if Arduino is busy in a measurement during a client connection?
Is client connection lost?
Is it possible to link a client connection to an interrupt??
you have to look at the whole code
void loop()
{
// if an incoming client connects, there will be bytes available to read:
Client client = server.available();
if (client == true) {
// read bytes from the incoming client and write them back
// to any clients connected to the server:
server.write(client.read());
}
// you can do your measurements here
}
Server.available() is non blocking (it does not wait for a connection) so it will return with a socket nr ( some value > 0 ) which is interpreted as true, or with 0 interpreted as false.
See - Ethernet - Arduino Reference -
robtillaart:
Server.available() is non blocking (it does not wait for a connection) so it will return with a socket nr ( some value > 0 ) which is interpreted as true, or with 0 interpreted as false.
See - Ethernet - Arduino Reference -
Hi robtillart,
thank you for your reply.
Yes, i saw that code and I had understood that Server.available() was a non blocking instruction.
In fact, my question was different.
What happen if i write a code that required "a lot of time" and Arduino can't execute Server.available() in time?
For example, i write a function that must read some values from different sensors. A client send a message to webserver on Arduino while this are measuring.
How can I interrupt measurement for managing client request?
thanks
What happen if i write a code that required "a lot of time" and Arduino can't execute Server.available() in time?
Then you will not get a connection ...
Arduino is only single threaded, so you cannot have a background process waiting for a network connection. Interrupts is no solution imho as interrupts should be as short as possible.
robtillaart:
Then you will not get a connection ...
Arduino is only single threaded, so you cannot have a background process waiting for a network connection. Interrupts is no solution imho as interrupts should be as short as possible.
You are right.
If Arduino is single threaded, how does the library support up to four concurrent connection (incoming or outgoing or a combination)?
If Arduino is single threaded, how does the library support up to four concurrent connection (incoming or outgoing or a combination)?
The chip in the ethernet shield does, and in the lib reflects that administratively.