I have been running Blazor application for multiple years now and I suffer from my TCP Socket listener always getting disconnected randomly.
I have tried both direct IIS hosting and plesk running on Windows (IIS)
My goal is to keep the TCP Socket listener running forever without being interrupted. I believe that the socket gets closed due to the website going idle sometimes.
Regards and thanks in advance!
2
Answers
you should make a multitask application which can control sockets in separate tasks and each socket must be in a single task so by entering a socket data by event management you can control all the sockets in your application.
by System.Net.Sockets(in C#) the Sockets from your website requests must be processed and a multitask application by System.Threading.Task can help you to do it.
your listener application in your server can be a windows service or a console application or even Windows form application(I used this and it works very good with sockets in my website)
controlling tasks needs precise checking of socket states to avoid lock or malfunctioning.
I hope this helps.
Try using SignalR with the BLazor app to establish a SignalR connection.
Also make sure your hosting environment doesn’t interfere with long-lived connections.