Skip to content

Instantly share code, notes, and snippets.

@velitasali
velitasali / Example.java
Last active September 23, 2023 19:33
Asynchronous & multithreaded TCP server/client example in Java
public static class Example {
public static void main(String[] argss) throws Exception {
int intStart = 6;
try (ServerSocket serverSocket = new ServerSocket()) {
serverSocket.bind(new InetSocketAddress(0));
Thread serverThread = new Thread(() -> {
try {
while (serverSocket.isBound()) {