Note that there are some explanatory texts on larger screens.

plurals
  1. POObjectOutput/InputStream only sends and recevies objects once
    text
    copied!<p>i'm trying to send an object that will hold some information through <code>ObjectOutputStream</code> using sockets. when i call the method <code>Client_Handler(String auth, String user)</code> and send the object it works fine, but when i call it again it doesn't work. I want to be able to use the connection to send the object with different data inside it many times. </p> <p>client:</p> <pre><code>public void Client_Handler(String auth, String user){ try{ socket2 = new Socket(serverAddress, 8080); User_Authorization us3 = new User_Authorization(); ObjectOutputStream out2 = new ObjectOutputStream(socket2.getOutputStream()); us3.set_name(user); us3.set_authorization(auth); out2.writeUnshared(us3); }catch(Exception e){ JOptionPane.showMessageDialog(null, e, "Error", JOptionPane.ERROR_MESSAGE); } } </code></pre> <p>server:</p> <pre><code>public class Conn implements Runnable{ private Socket socket; public static ServerSocket server ; public void go(){ Thread r = new Thread(this); try{ r.start(); }catch(Exception e){ JOptionPane.showMessageDialog(null, e, "Error", JOptionPane.ERROR_MESSAGE); } } @Override public void run() { try{ server = new ServerSocket(8080); socket = server.accept(); while(true){ Login.User_Authorization us = null; ObjectInputStream in = new ObjectInputStream(socket.getInputStream()); us = (Login.User_Authorization) in.readObject(); System.out.println(us.get_name()+ "he's " +us.get_authorization()); } }catch(Exception e){JOptionPane.showMessageDialog(null, e, "Error", JOptionPane.ERROR_MESSAGE);} } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload