java/java-socket-stream/src/main/java/org/example/DataServer.java
<reponame>aveek22/project-bunchpackage org.example;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Random;

public class DataServer {
    public static void main(String[] args) throws IOException {


        ServerSocket listener = new ServerSocket(9090);
        try{
            Socket socket = listener.accept();
            System.out.println("New connection" + socket.toString());

            try{
                PrintWriter out = new PrintWriter(socket.getOutputStream(), true);

                Random rand = new Random();

                while(true){
                    int i = rand.nextInt(100);
                    String s = "" + System.currentTimeMillis() + "," + i;
                    System.out.println(s);

                    out.println(s);

                    Thread.sleep(50);
                }
            }
            finally{
                socket.close();
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
        finally{
            listener.close();
        }





        System.out.println("Hello world!");
    }
}