Writing Data to a Client


try {
  ServerSocket ss = new ServerSocket(port);
  while (true) {
    try {
      Socket s = ss.accept();
      Writer out = new OutputStreamWriter(s.getOutputStream());
      out = new BufferedWriter(out);
      out.write("Hello " + s.getInetAddress() + " on port " 
       + s.getPort() + "\r\n");
      out.write("This is " + s.getLocalAddress() + " on port " 
       + s.getLocalPort() + "\r\n");
      out.flush();
      s.close();
    }
    catch (IOException e) {}
  }
}
catch (IOException e) { System.err.println(e); }

Previous | Next | Top | Cafe con Leche

Copyright 2000 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified September 6, 2000