FileDocCategorySizeDatePackage
EchoInputThread.javaAPI DocExample1107Sat Sep 09 20:51:00 BST 2000None

EchoInputThread

public class EchoInputThread extends Thread

Fields Summary
private InetAddress
server
private DatagramSocket
socket
private EchoOutputThread
output
private boolean
stopped
private int
port
Constructors Summary
public EchoInputThread(InetAddress ia, int port)

  
       
     
    this.server = ia;
    this.socket = new DatagramSocket();
    this.port = port;
  
Methods Summary
public java.net.DatagramSocketgetSocket()

    return this.socket; 
  
public voidhalt()

    this.stopped = true; 
  
public voidrun()


    try {
      BufferedReader userInput 
       = new BufferedReader(new InputStreamReader(System.in));
      while (true) {
        if (stopped) return;
        String theLine = userInput.readLine();
        if (theLine.equals(".")) break;
        byte[] data = theLine.getBytes();
        DatagramPacket theOutput 
         = new DatagramPacket(data, data.length, server, port);
        socket.send(theOutput);
        Thread.yield();
      }
    }  // end try
    catch (IOException e) {
      System.err.println(e);
    }