Hardware Reference
In-Depth Information
connections, only local connections. The Arduino will wait for connections
from the local host, but the local host is also the Linux side of the Arduino. This
means that when incoming connections arrive, they will be routed through the
Linux processor, leaving the AVR microcontroller side of the Arduino free to do
what it does best—control your sketches. To do this, use listenOnLocalhost() :
server.listenOnLocalHost();
The last step, after the object has been created, is to use begin() :
server.begin();
The server has now been created, and you can wait for clients to connect. The
difference between the Arduino Yún and other models using Ethernet or Wi-Fi
shields is the multitasking capacity. Although other Arduinos have to wait for
a client to connect, the Yún doesn't need to wait, The Linux server can handle
connections, and the Arduino can see how many clients are waiting and handle
connections as required. Your sketch is free to continue between connections.
All you have to do is wait for a client.
YunClient
The YunClient interface is used for all client-based calls on the Yún. Just like
the server, you must i rst create a YunClient object:
YunClient client;
To accept an incoming connection, you can talk with the YunServer:
YunServer server;
YunClient client = server.accept();
if (client)
{
// Client has connected
}
You can verify if a client is still connected using connected() :
result = client.connected();
This function returns a boolean : true if the client is still connected and false
if it has disconnected.
When a client has connected, you can read and write using standard Stream
functions:
String data = client.readString();
client.println("Thanks for connecting to my Yún");
When you i nish talking to a client, you can terminate the connection using
stop() :
client.stop();
 
Search WWH ::




Custom Search