FileDocCategorySizeDatePackage
SenderThread.javaAPI DocExample1110Sun Dec 12 10:53:46 GMT 2004None

SenderThread

public class SenderThread extends Thread

Fields Summary
private InetAddress
server
private DatagramSocket
socket
private boolean
stopped
private int
port
Constructors Summary
public SenderThread(InetAddress address, int port)

  
       
     
    this.server = address;
    this.port = port;
    this.socket = new DatagramSocket();
    this.socket.connect(server, 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 output 
         = new DatagramPacket(data, data.length, server, port);
        socket.send(output);
        Thread.yield();
      }
    }  // end try
    catch (IOException ex) {
      System.err.println(ex);
    }