import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
public class AnotherBeerServer {
public static void main(String args[]) throws Exception {
ServerSocket ssock = new ServerSocket(1234);
System.out.println("Listening");
Socket sock = ssock.accept();
ssock.close(); // no more connects
PrintStream ps = new PrintStream(sock.getOutputStream());
// ask for count
ps.print("count? ");
BufferedReader input = new BufferedReader(new InputStreamReader(sock
.getInputStream()));
// read and parse it
String line = input.readLine();
ps.println("");
int count = Integer.parseInt(line);
for (int i = count; i >= 0; i--) {
ps.println(i + " Java Source and Support.");
}
ps.close();
sock.close();
}
}
|