0

I am writing a Web application for copying files between servers.

I decided to write a WebSocket server which will receive and send relevant messages (that is communicate with a browser), start and stop copying processes.

Accordingly my design decision, there is at most one copying process for a given user. A user does not "see" copying processes of other users. But one user may open multiple browser windows and thus have multiple connections to my WebSocket server.

When a copying process starts, the relevant user receives { "type": "Started" } JSON message. This may be a reply to the request to start copying files either from the current window or an other window of the same user.

When receiving { "type": "Started" } message, the JavaScript should show dialog "Copying files..." with "Interrupt" button (to interrupt copying in the middle). The dialog automatically closes if copying finishes (with or without an error).

Also if the copying cannot start for some reason, the browser receives a { "type" : "Error" } message.

Now my question: Should the server immediately reply with some message (maybe { "type": "StartReply" }) after copying starts? Or is it enough that we anyway will receive { "type": "Started" } message in near future?

Also: Should I number "Start" messages and include its number in a "StartReply" message, to know which message is answer on which one?

0

If we receive an immediate reply { "type": "StartCopying" } from the server on a browser's request to start copying, the workflow may go as follows:

  1. Show "Sending data..." widget and disable the UI on the page.

  2. Send copying request to the server.

  3. After we receive the "immediate reply", show "Copying files..." dialog with "Interrupt" button. (Alternatively, we may receive an error message from the server, show this message in an alert and dismiss "Sending data..." widget.)

  4. Ignore "Started" message from the server, because the dialog is already shown.

If we are not going to receive an immediate reply { "type": "StartCopying" } from the server, but rely on "Started" message which the server broadcasts to all open windows with our Web application, the workflow is as follows:

  1. Show "Sending data..." widget and disable the UI on the page. (Also store in a JavaScript variable that the reason for showing "Sending data..." widget was that we requested copying files.)

  2. Send copying request to the server.

  3. Wait for either error or "Started" message from the server.

  4. On either message (if the above mentioned variable tells that the reason for showing "Sending data..." widget was that we requested copying files) dismiss "Sending data..." widget, and if it is a "Started" message, show the "Copying files..." dialog.

Thus both workflows work fine, but the second is simpler. I am going to choose the second one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.