Lasitha Yapa
Lasitha Yapa

Reputation: 4609

How to send a DatagramPacket to multiple ip addresses?

I'm trying to make a simple network multiplayer game in java. In the server program I take DatagramPackets from every clients including their details (in a String). Then I add them into a HashMap and I want that HashMap to be sent to all players.

server.receive(packet);
String data=new String(packet.getData(),0,packet.getLength());
String[] usrData=data.split("=");
clients.put(usrData[0], usrData[1]);
makePacket();
//here I want to send HashMap to send to all clients.

Question is how can i send a packet to multiple computers?

Upvotes: 1

Views: 1471

Answers (1)

Mahmoud Hashim
Mahmoud Hashim

Reputation: 108

You need to use a MulticastSocket on the recipient(client) side, take a look at this tutorial from Oracle Broadcasting to Multiple Recipients

Upvotes: 2

Related Questions