From: <jo...@us...> - 2008-04-04 07:46:06
|
Revision: 229 http://mspsim.svn.sourceforge.net/mspsim/?rev=229&view=rev Author: joxe Date: 2008-04-04 00:45:50 -0700 (Fri, 04 Apr 2008) Log Message: ----------- fixed network connection (server) to avoid sending back to the source radio. Modified Paths: -------------- mspsim/se/sics/mspsim/util/NetworkConnection.java Modified: mspsim/se/sics/mspsim/util/NetworkConnection.java =================================================================== --- mspsim/se/sics/mspsim/util/NetworkConnection.java 2008-04-04 06:53:36 UTC (rev 228) +++ mspsim/se/sics/mspsim/util/NetworkConnection.java 2008-04-04 07:45:50 UTC (rev 229) @@ -104,19 +104,20 @@ } // Data incoming from the network!!! - private void dataReceived(byte[] data, int len) { + private void dataReceived(byte[] data, int len, ConnectionThread source) { int[] buf = new int[len]; if (listener != null) { for (int i = 0; i < buf.length; i++) { buf[i] = data[i]; } - // Send this data to the transmitter + // Send this data to the transmitter in this node! listener.transmissionStarted(); listener.transmissionEnded(buf); } + // And if this is the server, propagate to the others if (serverSocket != null) { - dataSent(buf); + dataSent(buf, source); } } @@ -126,6 +127,12 @@ // Data was sent from the radio in the node (or other node) and should // be sent out to other nodes!!! public void dataSent(int[] data) { + dataSent(data, null); + } + + // Data was sent either from radio, or came from another "radio" - + // and if so it should be propagated to all others. + public void dataSent(int[] data, ConnectionThread source) { if (connections.size() > 0) { for (int i = 0; i < data.length; i++) { buf[i] = (byte) data[i]; @@ -134,7 +141,8 @@ for (int i = 0; i < cthr.length; i++) { if (cthr[i].isClosed()) { connections.remove(cthr); - } else { + // Do not write back to the source + } else if (cthr[i] != source){ try { cthr[i].output.write((byte) data.length); cthr[i].output.write(buf, 0, data.length); @@ -215,8 +223,7 @@ System.out.println("NetworkConnection: Read packet with " + len + " bytes"); printPacket(buffer, len); } - - dataReceived(buffer, len); + dataReceived(buffer, len, this); } } catch (IOException e) { e.printStackTrace(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |