Question

I have a serious problem in mac os x. Im developing an backup distributed application in mac os x. The application have to send a file to the network and the peers of network have to backup the file. So for this purpose im using 2 threads: first thread read the file from system and upload them to network using an protocol predefined by me and second thread is waiting for messages from the other peers in the network.

Im using the follow code:

Thread to send:

String putchunk_string = "MESSAGE TO SEND...";
DatagramSocket socket = new DatagramSocket ();
string address = "225.0.0.2"; // ip of multicast 
string port = 4002; // port of multicast 

byte buf[] = putchunk_string.getBytes();

DatagramPacket pack = newDatagramPacket(buf,buf.length,
InetAddress.getByName(address),port);
socket.send(pack);
socket.close();

Thread to receive:

started=true;
MDataChannel = new MulticastSocket(4002);
MDataChannel.setLoopbackMode(true);
MDataChannel.setTimeToLive(1);
MDataChannel.joinGroup(InetAddress.getByName("225.0.0.2"));
while(started)
{
  received_packet = new DatagramPacket(message, message.length);
  MDataChannel.receive(received_packet);

  //....More code to parse the message
}

My problem is: I have to computers connected to a router, one windows and other mac os x and i have the same code in both. When i send a file from windows to mac os x computer all is good. The mac computer receive packets from windows computer and windows computer dont receive any packets because i have disable loopback on multicastsocket with setloopbackmode. But when i send from mac os x computer to windows i have a problem: the windows computer receive the packets but the mac computer also receives the packets and he should not receive because are the own packets and i have setloopbackmode(true) that disable loopback.

Im using java 1.6 in os x but i already try 1.7.

Im not doing this right or this is a bug of java multicast sockets on osx? Regards

Was it helpful?

Solution

I think i discovered the answer..basically windows consider a loopback datagram when destination machine is equal to source machine..Mac os x consider a loopback datagram when destination socket is equal to source socket.

Regards

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top