Skip to main content

multicasting in java

1 reply [Last post]
Joined: 2003-06-16

i wrote a program that communicates with the same program running on another computer. it's like an instant messenger program. problem is that is seems to only work when both programs are being run on the same network. I need to run it off of my schools unix machine and simultaneously run it from my home windows PC (different networks). i send datapackets through datasockets, while concurrently checking the multicastsocket.

this is what i use to read the multicastsocket:

byte[] buf = new byte[1024];
packet = new DatagramPacket(buf, buf.length);
String answer = new String(packet.getData(), 0, packet.getLength());

and this is my sending data procedure:

String mes = inputField.getText();
DatagramSocket socket = new DatagramSocket();
DatagramPacket packet2 = new DatagramPacket(mes.getBytes(), mes.length(), group, port.intValue());

this is how i connect:

String host = (String)ipBox.getSelectedItem();
port = new Integer(portText.getText());
msocket = new MulticastSocket(port.intValue());
group = InetAddress.getByName(host);

if anyone could help i'd really appreciate it. i've been working on this (as well as different methods of connecting) for 5 hours today.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-02-17

This is a common question (well, about the program only running on the same network (eg/LAN)).
The reason is, the port that you're using is closed for access to the internet, but can be used on the private network.

I recommend using a port that is typcally open on all/most machines: 80 (typically for HTTP).
Unless you have permission to open the port you're currently using on your school computers.

I'm guessing that you're writing some kind of trojan for your school computers? Or something else malicious/annoying. :P .. Ermm .. good luck. lol.

Rob <