Question about EthernetUDP programming

I have some questions about this example from the Refence page.

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 177);

unsigned int localPort = 8888; // local port to listen on

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
// start the Ethernet and UDP:
Ethernet.begin(mac,ip);
Udp.begin(localPort);
}

void loop() {
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write("hello");
Udp.endPacket();
}

------------- Question 1 -----------------

First what does this line exactly do?

IPAddress ip(192, 168, 1, 177);

What is the first word IPAddress doing?

------------- Question 2 -----------------
About the library functions Udp.remote and Udp.remotePort.

Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());

Where in the example above should I set this values for my remote Arduino?

Regards, Wim

First what does this line exactly do?
IPAddress ip(192, 168, 1, 177);

This creates an ipv4 address for the w5100. It is the ip of your ethernet shield.

About the library functions Udp.remote and Udp.remotePort.
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());

This is for responding to a UDP packet sent by a remote device.
Udp.remoteIP() returns the ip of the sender of the last UDP packet.
Udp.remotePort() returns the port of the sender of the last UDP packet.

If you want to see a good example (albeit a bit complex) is the NTP example. It initiates a send and receives a response packet if all went well.

Thanks for the quick reply, but in the example I'm WRITING to my 2nd Arduino.

And this second Arduino is not writing but waiting ( by checking :

int packetSize = Udp.parsePacket();So there is no LAST PACKET.

So where does the example above know where to send the message to?

Something like this:

IPAddress targetIP(1,2,3,4);
int targetPort = 8888;

Udp.beginPacket(targetIP, targetPort);

I can see why it does not work.

I hooked up a laptop with WireShark and this shows me the ARP

Broadcast who has 10.10.10.1 ? Tell 10.10.10.160

So the question is why ARP ask for the MAC of 10.10.10.1 instead of 10.10.10.170

byte mac[] = {0x11,0x22,0x33,0x44,0x55,0x66 };
IPAddress ip(10,10,10,160);
unsigned int localPort = 7777;
EthernetUDP Udp;

void setup()
{
Ethernet.begin(mac,ip);
Udp.begin(localPort);
}

void loop()
{
IPAddress remoteIP(10,10,10,170);
int remotePort = 8888;
Udp.beginPacket(Udp.remoteIP(),Udp.remotePort());
Udp.write("Hello.");
Udp.endPacket();
delay(1000);
}

I don't like using variables that match those in the library. It causes confusion. But if you insist on using remoteIP and remotePort, this is how.

void loop()
 {
  IPAddress remoteIP(10,10,10,170);
  int remotePort = 8888;
  // note no Udp. preceding either of the parameters
  Udp.beginPacket(remoteIP,remotePort);
  Udp.write("Hello.");
  Udp.endPacket();
  delay(1000);
 }

Thanks, works now........

Wim