package primer_12; import java.net.*; import java.io.*; public class ReceiverRunnable implements Runnable { private DatagramSocket socket; // private boolean stopped = false; // nepotrebno u ovoj implementaciji /* dodato */ private SenderRunnable sender; /* ubacen drugi konstruktor umesto ovoga public ReceiverThread(DatagramSocket ds) throws SocketException{ socket = ds; } */ /* dodato */ public ReceiverRunnable(SenderRunnable sender) throws SocketException{ socket = sender.getSocket(); this.sender = sender; } /* public void halt(){ stopped = true; } */ public void run(){ byte[] buffer = new byte[65507]; while(true){ if(sender.isStopped())return; DatagramPacket dp = new DatagramPacket(buffer, buffer.length); try{ socket.receive(dp); String s = new String(dp.getData(), 0, dp.getLength()); System.out.println(s); Thread.yield(); }catch(InterruptedIOException ex){ }catch(IOException ex){ System.err.println(ex); } } // end while } }