Back to the topics, this is exactly what I wanted. By the way, this amazing tutorial helped me a lot.
Main.java
public class Main { public static void main(String args[]) { ChatServer server = null; server = new ChatServer(Integer.parseInt("8084")); } }
and the ChatServer.java class extends Runnable
public class ChatServer implements Runnable { private ChatServerThread clients[] = new ChatServerThread[50]; private ServerSocket server = null; private Thread thread = null; private int clientCount = 0; public ChatServer(int port) { try { System.out.println("Binding to port " + port + ", please wait ..."); server = new ServerSocket(port); System.out.println("Server started: " + server); start(); } catch(IOException ioe) { System.out.println("Can not bind to port " + port + ": " + ioe.getMessage()); } } public void start() { if (thread == null) { thread = new Thread(this); thread.start(); } } .... pleas continue with the tutorial
So, in the main method Runnable starts and a new thread, as shown in the figure, public void start() { is created using runnable. This causes the JVM to continue the process until the project or debugger exits.
Btw, the same as Joachim Sauer, published in his answer.
source share