On 1/18/06, Ross Werner <[EMAIL PROTECTED]> wrote:
> (p.s. this is super-trivial to do in just about any modern programming
> language. It's about four lines of perl, php, and about a dozen in Java.
> The phrase "socket programming" shouldn't scare you away.)

Actually, it's 16 lines of code in Java (ignoring whitespace):

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

public class NetEcho {

  public static void main(String[] args) throws Exception {
    ServerSocket serverSocket = new ServerSocket(8081);

    while (true) {
      byte[] data = new byte[1024];
      int actualRead = 0;
      Socket clientSocket = serverSocket.accept();
      InputStream is = clientSocket.getInputStream();

      while ((actualRead = is.read(data)) > -1)
        System.out.print(new String(data, 0, actualRead));

      clientSocket.close();
    }
  }

}

-Bryan

/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to