package org.AutoHealerAndClusterSearch.testTransmitting;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;

public class Sender {
    public static void main(String[] args) {
        String serverHost = "localhost";
        int serverPort = 12345;

        try {
            // Establish a TCP connection to the server
            Socket socket = new Socket(serverHost, serverPort);

            // Get the OutputStream from the socket
            OutputStream outputStream = socket.getOutputStream();

            // Create an ObjectOutputStream to serialize the object
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);

            // Create and serialize the object
            MyClass obj = new MyClass();  // The object you want to serialize
            obj.sth = "hello Mr.Salameh";
            objectOutputStream.writeObject(obj);

            // Flush and close the output stream and socket
            objectOutputStream.flush();
            objectOutputStream.close();
            socket.close();

            System.out.println("Object sent successfully.");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}