Hardware Reference
In-Depth Information
In the previous connection example, the IP address was dei ned as an array
of bytes:
byte ip[] = { 192, 168, 0, 10 };
It is possible to use the IPAddress class to simplify writing a list of IP Addresses.
The IP Address class takes four parameters; the four parts of an IP address.
// The DNS server IP
IPAddress dns(192, 168, 0, 1);
// The Router's address (the gateway)
IPAddress gateway(192, 168, 0, 1);
// The IP subnet
IPAddress subnet(255, 255, 255, 0);
// The Arduino's IP address
IPAddress ip(192, 168, 0, 10);
Ethernet.begin(mac, ip, dns, gateway, subnet);
Arduino as a Client
The Arduino is an excellent Ethernet client; it can reliably initiate connections to
servers, send data from sensors, and receive data from the server. When using
the Arduino as a client, you must use the EthernetClient object.
EthernetClient client;
A client connects to a server. The term “server” designates any network con-
nected device that a client connects to fetch or upload information. On a home
network, this can be just about anything. Most home modems have an internal
web server that allows you to coni gure it and to look at statistics. Your com-
puter might have a server application installed (either a web server or an FTP
server), and even if your PC is a client to the modem, it can still be a server for
other devices.
A server is therefore just about anything—a computer, a network device, even
another Arduino. A client is also just about anything, even a piece of hardware
that requires the service provided by a server. The client must connect to the
server, and in Arduino you make a connection with connect() . To connect to
a server, you need one of these two things: either the IP address of the server
or the domain name and the port.
result = client.connect(ip, port);
result = client.connect(dns, port);
The ip parameter is either an array of 4 bytes or an IPAddress object. The port
parameter is an int and is the port on the server to which you want to connect.
 
Search WWH ::




Custom Search