From: <ni...@us...> - 2008-04-24 15:31:09
|
Revision: 264 http://mspsim.svn.sourceforge.net/mspsim/?rev=264&view=rev Author: nifi Date: 2008-04-24 08:29:13 -0700 (Thu, 24 Apr 2008) Log Message: ----------- cleanup 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-24 15:18:03 UTC (rev 263) +++ mspsim/se/sics/mspsim/util/NetworkConnection.java 2008-04-24 15:29:13 UTC (rev 264) @@ -78,7 +78,7 @@ public void addPacketListener(PacketListener pl) { listener = pl; } - + private void setupServer(int port) { try { serverSocket = new ServerSocket(port); @@ -107,15 +107,15 @@ // all other nodes private void dataReceived(byte[] data, int len, ConnectionThread source) { int[] buf = new int[len]; + for (int i = 0; i < buf.length; i++) { + buf[i] = data[i]; + } if (listener != null) { - for (int i = 0; i < buf.length; i++) { - buf[i] = data[i]; - } // 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, source); @@ -123,7 +123,7 @@ } - byte[] buf = new byte[256]; + private byte[] buf = new byte[256]; // Data was sent from the radio in the node (or other node) and should // be sent out to other nodes!!! @@ -137,7 +137,7 @@ if (connections.size() > 0) { for (int i = 0; i < data.length; i++) { buf[i] = (byte) data[i]; - } + } ConnectionThread[] cthr = connections.toArray(new ConnectionThread[connections.size()]); for (int i = 0; i < cthr.length; i++) { if (cthr[i].isClosed()) { @@ -159,10 +159,10 @@ } } } - + private void printPacket(byte[] data, int len) { for (int i = 0; i < len; i++) { - System.out.print("" + Utils.hex8(data[i]) + " "); + System.out.print(Utils.hex8(data[i]) + " "); } System.out.println(); } @@ -214,9 +214,9 @@ @Override public void run() { if (DEBUG) System.out.println("NetworkConnection: Started connection thread..."); - while (socket != null) { - int len; - try { + try { + while (socket != null) { + int len; len = input.read(); if (len > 0) { input.readFully(buffer, 0, len); @@ -226,11 +226,11 @@ } dataReceived(buffer, len, this); } - } catch (IOException e) { - e.printStackTrace(); - socket = null; } + } catch (IOException e) { + e.printStackTrace(); + close(); } - } + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |