I want to transfer an object from a client to a server, I found a bunch of examples, I realized that I needed an object stream and what method to call.
SERVER
startB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { thread = new Thread(new Runnable() { public void run() { try { int i = 0; // ΡΡΡΡΡΠΈΠΊ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΠΉ server = new ServerSocket(6666, 0, InetAddress.getByName("localhost")); System.out.println("server is started"); // ΡΠ»ΡΡΠ°Π΅ΠΌ ΠΏΠΎΡΡ while (true) { // ΠΆΠ΄ΡΠΌ Π½ΠΎΠ²ΠΎΠ³ΠΎ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΡ, ΠΏΠΎΡΠ»Π΅ ΡΠ΅Π³ΠΎ Π·Π°ΠΏΡΡΠΊΠ°Π΅ΠΌ ΠΎΠ±ΡΠ°Π±ΠΎΡΠΊΡ ΠΊΠ»ΠΈΠ΅Π½ΡΠ° // Π² Π½ΠΎΠ²ΡΠΉ Π²ΡΡΠΈΡΠ»ΠΈΡΠ΅Π»ΡΠ½ΡΠΉ ΠΏΠΎΡΠΎΠΊ ΠΈ ΡΠ²Π΅Π»ΠΈΡΠΈΠ²Π°Π΅ΠΌ ΡΡΡΡΡΠΈΠΊ Π½Π° Π΅Π΄ΠΈΠ½ΠΈΡΠΊΡ new NewConnection(i, server.accept()); i++; System.out.println(server.getInetAddress()); } } catch (Exception e) { } // Π²ΡΠ²ΠΎΠ΄ ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠΉ } }); thread.setDaemon(true); thread.start(); } }); public class NewConnection extends Thread { ClientsMessage msg = null; Socket s; int num; NewConnection(int num, Socket s) { this.num = num; this.s = s; setDaemon(true); setPriority(NORM_PRIORITY); start(); System.out.println("Got client"); try { ServerProgram.inStr = s.getInputStream(); ServerProgram.inObject = new ObjectInputStream(ServerProgram.inStr); } catch (Exception e) { e.printStackTrace(); } } public void run() { while(true) { try{ msg = (ClientsMessage) ServerProgram.inObject.readObject(); System.out.println(msg.name + " " + msg.surname); } catch (Exception e) { e.printStackTrace(); } } }