123456789101112131415161718192021222324 |
- import java.io.*;
- import java.net.*;
- public class TCPClient {
- public static void startClient() {
- String serverAddress = "127.0.0.1"; // Make sure this matches your TypeScript server
- int port = 12345;
- try (Socket socket = new Socket(serverAddress, port);
- BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- PrintWriter writer = new PrintWriter(socket.getOutputStream(), true)) {
- // Send a message to the TypeScript server
- writer.println("Hello, Server from Java!");
- // Receive response from the TypeScript server
- String response = reader.readLine();
- System.out.println("Server says: " + response);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
|