Problem with code for sending UDP packets

Hello guys

I've just upload/checked the code below for sending UDP packets over ethernet when 2 contacts are closed.
The arduino works and the code is uploaded but i think he doesn't sen UDP packets.
Please can somebody check my code?

#include <SPI.h> 
#include <Ethernet.h>
#include <EthernetUdp.h>

// the media access control (ethernet hardware) address for the shield:
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//the IP address for the shield:
byte ip[] = { 192, 168, 1, 1 };  

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

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

void setup()
{
  
  Ethernet.begin(mac, ip);                        //Start the Ethernet and UDP
  Udp.begin(localPort);
  Serial.begin(9600);
  
  pinMode(22, INPUT);                            // Sets the digital pin as input
  pinMode(23, INPUT);                            // Sets the digital pin as input
  pinMode(24, INPUT);                            // Sets the digital pin as input
  pinMode(25, INPUT);                            // Sets the digital pin as input
}

void loop()
{
   if (digitalRead(22) && digitalRead(23))
        sendPacket("g1");

   if (digitalRead(24) && digitalRead(25))
        sendPacket("g2");
}

void sendPacket(char *contents)
{
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(contents);
    Udp.endPacket();
}

Thanks in advance

Leon

I don't see any code to set Udp.remoteIP() or Udp.remotePort().

You have to call UDP.parsePacket() first:

If you are not responding to a received packet then you should probably use something like:

IPAddress destinationIP(192, 168, 1, 177);  // Address of target machine
unsigned int destinationPort = 6555;      // Port to send to


    Udp.beginPacket(destinationIP, destinationPort);

Hi
I don't quite understand what u mean. Could u me show step by step what the problem is?
I don't know what to do with your advice. Many thanks!