Hey guys,
I'm working on a chat program where a UDP console-based chat program's client sends a message to the server and subsequently the server sends it to all other clients on the network. As of this moment the program is able to:
- Client send message to server
- Server receives message
- Server sends message to "all" clients on the LAN
Server just sends the message back to the sending client and not other client
....... //<-- Before this there's the input message which works fine and some initiation of variables byte outData[] = outMSG.getBytes(); // address is just an arrayList of IP addresses for (int i = 0; i < address.size(); i++) { // i was thinking that by iterating through the list the message will be sent to all addresses but this does not seem to be the case since it's not working InetAddress cAddress = InetAddress.getByName(addressList.get(i)); int cPort = receivingPacket.getPort(); DatagramPacket outPacket = new DatagramPacket(outData, outData.length, cAddress, cPort); socket.send(outPacket); }
I also believe my client is working as intended and the problem just lies with the server. I can't seem to make the server send the message to a different client (different to the sending client). Any help will be appreciated and if you need more code please let me know