Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>when i call the method Client_Handler(String auth, String user) and send the object it works fine, but when i call it again it doesn't work.</p> </blockquote> <p>Because, each time you are calling <code>Client_Handler(String auth, String user)</code> method you are trying to establish a new connection with Server via <code>socket2 = new Socket(serverAddress, 8080);</code> which is terminating the previous connection. That's why you are getting <code>EOFException</code> exception. You should create the <code>socket2</code> object once before calling <code>Client_Handler</code> method. And while calling the <code>Client_Handler</code> method simply use the initialized Socket <code>socket2</code>.<br></p> <p>You code could something be like this at client side:</p> <pre><code>Socket socket2; ObjectOutputStream out2 = null; public void mainMethod() { try { socket2 = new Socket(serverAddress, 8080); out2 = new ObjectOutputStream(socket2.getOutputStream()); boolean canSend = true; while (canSend) { canSend = Client_Handler("authentication","user"); } } catch (Exception ex) { ex.printStackTrace(); } finally { if (out2!=null) { try { out2.close(); } catch (Exception ex) { ex.printStackTrace(); } } } } public boolean Client_Handler(String auth, String user) { try { User_Authorization us3 = new User_Authorization(); us3.set_name(user); us3.set_authorization(auth); out2.writeUnshared(us3); }catch(Exception e) { JOptionPane.showMessageDialog(null, e, "Error", JOptionPane.ERROR_MESSAGE); return false; } return true; } </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