I actually work on a web application (ASP.NET MVC) which sends command to a thick-client application (that I can not modify) on a local network in TCP/IP. I need that the thick-client application respond to my command or give me information, so the connection need to be open all the time. I create a loop that checks the server response like that :
public static async void getMessage()
{
while(true)
{
// Buffer to store the response bytes.
Byte[] data = new Byte[100000];
// String to store the response ASCII representation.
String responseData = String.Empty;
// Read the first batch of the TcpServer response bytes.
Int32 bytes = await stream.ReadAsync(data, 0, data.Length);
if (bytes == 0) continue;
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
Debug.Write(responseData);
await stream.ReadAsync(data, 0, data.Length);
}
}
That's actually working, and I received the response from the server, but the browser is "waiting for localhost" all the time, so is there a better way to do that, without the loop on the browser?
Thank you a lot !
This sounds like a really good case for a websocket. In an MVC app, you'd typically use SignalR: http://www.asp.net/signalr
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With