Note that there are some explanatory texts on larger screens.

plurals
  1. POBlocking read from an input TCP socket
    primarykey
    data
    text
    <p>I am currently working on a project for a distributed systems course where we have to implement a small sensor network in java. The sensors send the temperature every x seconds to an admin node (that is also a sensor), that records them. Upon request, an user node connects to the admin node and receives the mean of the detected temperatures. One of the issues is that the admin node can "fail". Before failing it actually sends a message to the user node, that needs to send a special packet to one of the other regular nodes that will become the new admin. The user node communicates with the admin with a TCP connection trough which it sends a "request" packet and receives a packet containing the temperature. I am currently using java.net.socket to implement this. </p> <p>The problem comes when the admin fails. In normal condition, could create a new thread that waits for this "fail" message from the server and then creates a new socket with the newly selected admin node. But, if the admin fails before it sends a message in response to a user request, the user node will be indefinitely waiting, because it is reading from an input stream.</p> <p>In particular, I am using the following lines to create the socket and the input stream:</p> <pre><code> this.socket = new Socket(this.serverAddress,this.serverPort); this.in = new DataInputStream(socket.getInputStream()); </code></pre> <p>and the following line in an while loop to read the response temperature.</p> <pre><code> String data = in.readUTF(); </code></pre> <p>How would you suggest to handle this situation?</p> <p>Also, I was thinking to use the same TCP connection for receiving the "fail" message from the admin node. How can I support this?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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