I am recently trying to combine C# and JavaScript together in client side only. I follow the instruction in here to invoke functions in a C# DLL in JavaScript. Now I have a question regarding push data from C# DLL to JavaScript. Suppose the C# DLL includes a function collecting data from a sensor periodically (30 data every second). I would like to draw the data in a browser by pushing the data from the DLL to JavaScript and then draw in the website page. Can anyone suggest a possible way to solve this problem? Thank you.
1 Answer
One method can be to create a TCP server on the C# client/server application and connect to the server from JavaScript; after which, you can send the data.
You can also create a web socket with JavaScript and then send data to that via the ActiveX control. Executing it in ActiveX, then sending the queries. http://www.codeproject.com/Articles/617611/Using-WebSocket-in-NET-4-5-Part-1
A problem with both of these solutions is the fact that you can't use DLL's ONLY to do that, you need a service/pooling service.
The best method to do this (which may/not work for your specific case) is to create a simple server with C# and then use an observable model in JS to fetch and render the data. This way, you can get rid of the code which checks if the data is being sent and see the changes in real-time.
Use a framework like AngularJS and you'll be off. https://docs.angularjs.org/api/ng/directive/ngModel