Note that there are some explanatory texts on larger screens.

plurals
  1. POBest way for a Server to notify a Client it has initialised
    primarykey
    data
    text
    <p><strong>Edit 2</strong> Renamed question</p> <p>I have some Java code (the Client) which starts a separate process written in C# (the Server). The C# process is passed a pair of sockets (one to <code>listen</code> on, one to <code>reply</code> to); when it receives a connection on the <code>listen</code> socket, it processes the data sent and replies to the same IP on the <code>reply</code> socket. The process is designed to be running continuously, listening for connections and replying. Since it always replies to the same IP it can of course accept messages from many different clients. The Java code in turn listens to the process for its responses.</p> <p>Although quite a basic system the setup is working perfectly except for one issue. The Java code determines whether the process is running or not before sending a message, using methods like <code>Process.waitFor()</code> and <code>Process.exitValue()</code>. The problem I have is that the process is not ready to actually receive messages for a few seconds after it starts.</p> <p>My question is <strong>what is the best pattern to use for a server to tell a client it has started?</strong> The options I have thought of include:</p> <ol> <li>The Java process repeatedly trying to connect and send a test message, only halting when response is received</li> <li>The C# process broadcasts to a list of client IPs when it has started</li> <li>The Java simply waits a few seconds and then tries to connect</li> </ol> <p>I don't particularly like any of the above options, although I am leaning towards option 1). Is there any established pattern to use here?</p> <p>Note that I do not want to use any existing framework for this communication. The actually messages are very simple, with the messaging code at both ends 'manually' encoding and decoding to a byte stream - for the sake of saving a hundred odd lines of code I don't wish to change this.</p> <p>I realise this type of 'best way' question could be closed for being unconstructive, but I have googled for hours and come up with nothing. Any help or advice would be much appreciated :)</p> <p><strong>Edit - some more context</strong></p> <p>Although most client/server relationships involve the server starting long before any client tries to connect (thus avoiding this problem entirely), the setup here is slightly the different.</p> <p>In this case, the client effectively starts the server as and when it needs it. In addition, if the client can see the server process isn't running it starts a new process. In both these cases the client needs to know when the server has initialised (not just when the process has started) before sending its first message</p>
    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.
 

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