TCP server that runs on port 9090 - Java Network

Java examples for Network:ServerSocket

Description

TCP server that runs on port 9090

Demo Code

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

public class Server {

    public static void main(String[] args) throws IOException {
        ServerSocket listener = new ServerSocket(9090);
        try {// www. j  a  va2  s .c  o m
            while (true) {
                Socket socket = listener.accept();
                try {
                    PrintWriter out =
                        new PrintWriter(socket.getOutputStream(), true);
                    out.println("asdf");
                } finally {
                    socket.close();
                }
            }
        }
        finally {
            listener.close();
        }
    }
}

Related Tutorials