Ensuring the client is connected and KeepAliveInterval #133
Unanswered
NickThissen
asked this question in
Q&A
Replies: 1 comment
-
Hi @NickThissen thanks for your note. Nothing wrong at all with the way you've written the code for question #1. On your second question re: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I'm using your websocket implementation for a very simple messaging bus between two applications running on the same computer. The server application simply listens for a message, and one or more clients can connect to send messages. Both the server and client applications can stop and start "at will", so I have to handle the cases where e.g. the server keeps running but the client stops and starts, or vice versa the client keeps running but the server application stops and later starts again.
Right now I implemented the following logic which seems to work well:
WatsonWsClient
is initialized and connected. If not initialized yet, I create a new instance and start it. If already connected, I just continue.ServerDisconnected
event), I stop the client and dispose it, and set it back to null. The next time the application is instructed to send a new message, the client is null so a new instance is created.Question 1: Is this a reasonable approach? I am not worried about performance, the messages are not sending multiple times per second, it's just an occassional single message and it does not matter if there is even half a second delay before it reaches the server.
Question 2: How does the client
KeepAliveInterval
come into this? I set it to 10 seconds and I was expecting the client to disconnect itself after no activity for 10 seconds, after which I should also make sure the client is disposed properly and re-created next time. However, nothing seems to happen at all. What doesKeepAliveInterval
actually do?Thanks!
For some details, before every "send message" I ensure the connection is available like this:
Beta Was this translation helpful? Give feedback.
All reactions