How to implement transfer control using "TCP urgent data" in Java.
I implemented a client-server application for transferring a file using the TCP protocol. Server is parallel. It is also necessary to implement transmission control using urgent data. I did not find a solution on Java on the Internet.
Server class:
import javafx.beans.binding.Bindings;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
    private static final String FILE_PATH_SERVER = "C:\\Users\\anduser\\IdeaProjects\\Shafarenko_LR1\\src\\main\\resources\\fileServer.txt";
    public static final File FILE_SERVER = new File(FILE_PATH_SERVER);
    private ServerSocket serverSocket;
    public void start(int port) throws IOException {
        serverSocket = new ServerSocket(port);
        while (true)
            new ClientHandler(serverSocket.accept()).start();
    }
    public void stop() throws IOException {
        serverSocket.close();
    }
    private static class ClientHandler extends Thread {
        private Socket clientSocket;
        private DataOutputStream out;
        private FileInputStream in;
        public ClientHandler(Socket socket) {
            this.clientSocket = socket;
        }
        public void run() {
            try {
                out = new DataOutputStream(clientSocket.getOutputStream());
                out.writeInt((int) FILE_PATH_SERVER.length());
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                in = new FileInputStream(FILE_PATH_SERVER);
            } catch (IOException e) {
                e.printStackTrace();
            }
            while (true) {
                byte buf[] = new byte[8];
                int len = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (len == -1) {
                    break;
                }
                try {
                    out.write(buf, 0, len);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                try {
                    out.flush();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                clientSocket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Client class:
import org.apache.commons.lang3.RandomStringUtils;
import java.io.*;
import java.net.Socket;
public class Client {
    private String generatedFileClient = RandomStringUtils.randomAlphanumeric(10) + ".txt";
    private String FILE_PATH_CLIENT = "C:\\Users\\anduser\\IdeaProjects\\Shafarenko_LR1\\src\\test\\resources\\" + generatedFileClient;
    private Socket clientSocket;
    private FileOutputStream out;
    private DataInputStream in;
    private File fileCilent;
    public File getFileClient() {
        return new File(FILE_PATH_CLIENT);
    }
    public void getFile() throws IOException {
        int i = 0;
        int len;
        byte buf[] = new byte[8];
        int fileSize;
        fileSize = in.readInt();
        while (i < fileSize) {
            len = in.read(buf);
            if (len == -1) {
                break;
            }
            i += len;
            out.write(buf, 0, len);
            out.flush();
        }
        out.close();
    }
    public void startConnection(String ip, int port) throws IOException {
        clientSocket = new Socket(ip, port);
        out = new FileOutputStream(FILE_PATH_CLIENT);
        in = new DataInputStream(clientSocket.getInputStream());
    }
    public void stopConnection() throws IOException {
        in.close();
        out.close();
        clientSocket.close();
    }
}
Test:
public class TestClient {
    @Test(threadPoolSize = 10, invocationCount = 1000, timeOut = 0)
    public void givenClient() throws IOException, InterruptedException {
        SoftAssert softAssert = new SoftAssert();
        Client client = new Client();
        client.startConnection("127.0.0.1", 555);
        client.getFile();
        softAssert.assertTrue(FileUtils.contentEquals(Server.FILE_SERVER, client.getFileClient()), "The files differ!");
        client.stopConnection();
        softAssert.assertAll();
    }
}