Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Main {
    public static void main(String args[]) throws Exception {
        ServerSocket ssock = new ServerSocket(1234);
        Socket sock = ssock.accept();
        ssock.close();

        PrintStream pstream = new PrintStream(sock.getOutputStream());
        pstream.print("count? ");
        BufferedReader input = new BufferedReader(new InputStreamReader(sock.getInputStream()));
        String line = input.readLine();
        pstream.println("");
        int count = Integer.parseInt(line);
        for (int i = count; i >= 0; i--) {
            pstream.println(i);
        }
        pstream.close();
        sock.close();
    }
}