You are only sending the packet to yourself!

1
| socket = new DatagramSocket(5000); |
This is opening port 5000.
1
| sendPacket = new DatagramPacket(sendData, sendData.length, InetAddress.getLocalHost(),5000); |
This is sending to THIS machine at port 5000! The IP you are passing the function needs to be the destination IP you need.
You should use a different socket for the server than the clients - you will have all sorts of issues if 2 apps try to bind to the same socket.
In fact, the clients port should NOT be set - it will be allocated a free one (allowing you to run multiple clients on the same machine)
For example, use 5000 for the server, and let the client set its own:
Client code:
1 2 3 4 5 6 7
| socket = new DatagramSocket();
...blah blah ...
sendPacket = new DatagramPacket(sendData, sendData.length, <SERVER IP HERE>, 5000); |
And on the server:
1 2 3 4 5 6 7 8 9 10
| socket = new DatagramSocket(5000);
...blah blah ...
for(int i=0; i<nClients; i++) { sendPacket = new DatagramPacket(sendData, sendData.length, <CLIENT[i] IP HERE>, <CLIENT[i] PORT No. HERE>); socket.send(sendPacket); |
When the client logs in, you should record the IP and socket the client has sent the message with. After login, you should always check the IP matches the login IP from each client (to prevent spoofing).
Note also that NAT firewalls may change the port ID at any point, so whenever you receive a message (& have verified it is genuine) you should copy the port ID from the message again.
Hope this helps,
Dom