FileDocCategorySizeDatePackage
echoOutputThread.javaAPI DocExample600Thu Apr 03 15:25:02 BST 1997None

echoOutputThread.java

import java.net.*;
import java.io.*;

class echoOutputThread extends Thread {

  DatagramSocket theSocket;
  protected DatagramPacket dp;

  public echoOutputThread(DatagramSocket s) {
    theSocket = s;
    buffer = new byte[65507];
    dp = new DatagramPacket(buffer, buffer.length);
  }

  public void run() {

    while (true) {
      try {
        theSocket.receive(dp);
        String s = new String(dp.getData(), 0, 0, dp.getLength());
        System.out.println(s);
        Thread.yield();
      }
      catch (IOException e) {
        System.err.println(e);
      } 
     
    }  
  
  }

}