Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting into an ObjectInputStream repeatedly
    primarykey
    data
    text
    <p>I have multiple clients and one server. Server handles each client in one thread. Clients must send a custon object to the master. I checked <a href="https://stackoverflow.com/questions/1194656/appending-to-an-objectoutputstream/1195078#1195078">this</a> and <a href="https://stackoverflow.com/questions/3182240/java-io-streamcorruptedexception-invalid-type-code-ac">this</a>, which talk about the error <code>java.io.StreamCorruptedException: invalid type code: AC</code> which is exactly I'm having. </p> <p>But I didn't understood the proposed solution. He inherits the ObjectOutputStream and simple does not write the header in the second and following times the object must be sent. This is not working for me.</p> <p>Is there another solution to send custom objects throught TCP sockets? My clients gather their data every 10 seconds and re-created the object which is sent. </p> <p>I'm sorry if i'm being repetitive, I'm reading a lot of similar question but finding no answers to my scenario. </p> <p>Thanks in advance</p> <p><strong>EDIT</strong></p> <p>Send method (in the client)</p> <pre><code> public void TCPEchoClientSend(MonitoredData _mData) throws IOException { if (_mData == null) throw new IllegalArgumentException("Parameter: &lt;Monitored Data&gt; empty."); ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream()); // Send the encoded object to the server oos.writeObject(_mData); oos.close(); System.out.println("Client sent the monitored data package."); } </code></pre> <p>Receive </p> <pre><code>public static void handleEchoClient(Socket client, Logger logger) { try { MonitoredData mdata; // Get the input and output I/O streams from socket ObjectInputStream ois = new ObjectInputStream(client .getInputStream()); ObjectOutputStream oos = new ObjectOutputStream(client .getOutputStream()); // Receive until client closes connection, indicated by -1; while ((mdata = (MonitoredData) ois.readObject()) != null) { System.out.println("Got received data. Ready to save."); hdb.saveOrUpdate(mdata); System.out.println("Monitored Data arrived at home."); } // logger.info("Client " + _clntSock.getRemoteSocketAddress()+ // ", echoed " + totalBytesEchoed + " bytes."); } catch (IOException ex) { logger.log(Level.WARNING, "Exception in echo protocol", ex); } catch (ClassNotFoundException e) { logger.log(Level.WARNING, "Exception in echo protocol", e); } finally { try { client.close(); } catch (IOException e) { } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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