Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange/unexplainable behaviour of Eclipse and multicast packets
    text
    copied!<p>I have a very similar behaviour as described <a href="https://stackoverflow.com/questions/1264948/link-scope-ipv6-multicast-packets-suddenly-not-routable-on-a-macbook-pro">here</a>:</p> <ul> <li>running on a Mac Book Pro, Snow Leopard</li> <li>using Multicast Sockets to send and receive packets on localhost</li> </ul> <p>I'm using Eclipse and observed the following behaviour when the client / server are started from within the workspace:</p> <ul> <li>if the wireless interface (airport) is up and running, the client does <em>not</em> receive any packets</li> <li>if the interface is turned off, everything works as expected</li> </ul> <p>But what I don't understand is:</p> <ul> <li>if I create a JAR and run the code in any console -> all good! Just Eclipse seems not to like airport ;-)</li> <li>depending on what wireless network I'm connected to, the above behaviour might change, i.e. it also works if airport is enabled (for example @ Uni)</li> </ul> <p>Does anyone have an idea 'bout this?</p> <p>Cheers</p> <p>Below the straightforward code for server / client:</p> <pre><code>@Override public void run() { String multicastAddress = "224.0.0.2"; int multicastPort = 8000; MulticastSocket socket = null; try { try { InetAddress multicastGoup = InetAddress.getByName(multicastAddress); socket = new MulticastSocket(multicastPort); socket.joinGroup(multicastGoup); } catch (IOException e) { e.printStackTrace(); return; } byte[] buffer = new byte[1024]; while (true) { DatagramPacket packet = new DatagramPacket(buffer, buffer.length); System.out.println("BEFORE RECEIVE: listening on " + multicastAddress + ":" + multicastPort); socket.receive(packet); System.out.println("PACKET RECEIVED"); System.err.println("Client received: " + new String(packet.getData())); } } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { socket.close(); } } </code></pre> <p>Server:</p> <pre><code> public void run() { MulticastSocket socket = null; try { String multicastAddress = "224.0.0.2"; int multicastPort = 8000; InetAddress multicastGoup = InetAddress.getByName(multicastAddress ); socket = new MulticastSocket(multicastPort); socket.joinGroup(multicastGoup); byte[] data = new String("Teststring").getBytes(); while (true) { socket.send(new DatagramPacket(data, data.length, multicastGoup, multicastPort)); System.out.println("SERVER: Datagram sent"); Thread.sleep(1000); } } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { socket.close(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload