Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/example/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public class App {
public static void main(String[] args) {
System.out.println("Hello There!");
SocketServer.main();
}
}
33 changes: 33 additions & 0 deletions src/main/java/org/example/SocketServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.example;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketServer {

static void main() {
int port = 3000;

try (ServerSocket serverSocket = new ServerSocket(port, 64)) {

System.out.println("Server started at port: " + serverSocket.getLocalPort());

while (true) {
Socket socket = serverSocket.accept();
Thread.ofVirtual().start(() -> handleClient(socket));
}

} catch (IOException e) {
throw new RuntimeException(e);
}
}

static void handleClient(Socket socket) {
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}