Communicate between a browser application and .net Windows application - javascript

The requirement is to provide duplex communication methodology between .net client application which is a windows application and javascript application, which runs on the browser.
Flow is
1. User installs the client app on their machine.
2. User visits the website and logs in to the portal which hosts the javascript app.
3. If the user performs an activity on client .net app, javascript app requires to be notified.
4. If the user performs an activity on the javascript app on the browser the .net client application has to be notified.
Possible solutions tried out are
1. Web server .net client app, where javascript app connects to using web sockets. However given the .net client app might start the webserver on a different port than originally intended, if the ports in use, the javascript app might not be able to identify the port the web server is running on.
2. Have an activeX running on the javacript app. Both the active X and .net app will connect through local named pipes through WCF. Bad part is use of active X will show a pop up soon as you load the web application.
Would you know of a better solution for the problem?

We've successfully used WebSockets for duplex communications between in-browser Javascript and an external app running a WebSocket server. It's efficient and (at least as of last year) bypassed all browser sandbox restrictions. I'm not 100% understanding this part of your question:
However given the .net client app might start the webserver on a different port than originally intended, if the ports in use, the javascript app might not be able to identify the port the web server is running on
The .NET app can run a socket server on any port it wants. If you are writing both apps, I'm not seeing how synchronizing on a specific port would be an issue? Worst case scenario the desktop app could write the port to local storage, which your JS can grab via local storage. There are other ways to synch this as well.

SignalR is a communications API that has client libraries for both .NET and javascript, and the server library is built on the ASP.NET stack.
With it, you can build a solution that allows client (js) <-> server <-> client (.NET) communication.
Here are some useful links to get you started:
SignalR main page
Tutorials are here
Handling SignalR communication between servers in a farm
SO question: example of SignalR .NET client application

Related

Can a Request Be Made To a Desktop Application Over the Web?

I have a desktop application and I am using the Process.Start property in this application. Can I somehow send a request to this program over the web?
Note: I cannot install iis or similar things on the device as it is a company computer.
Typically, the desktop application would act as a client here, and contact the server (possibly the same server that runs the web app, possibly a slightly different server intended just for API access). It is possible for a browser application to talk to a desktop application, by having the desktop application install itself as a custom protocol handler - but this may require more permission than you are allowed on the desktop machine, and it is relatively complex. Having the desktop app talk to a server, and the browser app talk to a server, but not directly to each-other: is a simpler setup.
If you mean to do this without any kind of browser session on the same machine, then:
either the desktop app needs to be running as a client, connecting to a server, and listening for messages, or:
the app needs to be a server, and open an inbound TCP/UDP port, to listen for connections/messages
The second option presents much more security issues; in a lot of corporate scenarios, this could be disallowed and blocked by corporate firewalls, or could even have the network security folks arrive at your desk with a cardboard box for your things.
You will need to setup your server somewhere in the internet or inside company LAN.
Desktop app should connect to this server and keep connected, waiting for a data. Or you can check for a new data by a timer, if your scenario allows some delays.
When you need to make a request, you send data to your server (may be including client id or something similar to identify the exact instance of the desktop app).
The server forwards data to the desktop app and then forwards the app's response back to you.
Note: you will not able to connect directly to the desktop client without intermediate server, as most likely the company computer does not have "white" ip and is located behind the company's NAT.

Connecting WebSockets from browser to other applications

Presentation
My application is split in 3 parts :
C# .Net 5.0 desktop application that harvest and distribute data
Angular 10 static application that control the C# app (start/Stop) and
print the data in the form of charts for the user
Azure Function Rest API used as a backend for the Angular Static
Application (.NET core 3.1)
My goal is to have a WebSocket used for "real time" communication between the C# and Angular app instead of relying on Http Request to Azure Function REST api
I don't use a "classic" server like express.js. Azure Function replaces it fully.
Because of that, I'm using the service Azure WebPubSub to host the sockets.
Problem : I cannot connect the websocket I create from Angular (Browser Application).
The problem doesn't come from WebPubSub because the WebSockets are fully working (sending & receiving) between my C# app, Azure Functions and even some node.js test scripts.
Also, my web socket created in the browser app can communicate with itself but no other apps get the message send from my websocket in browser app.
Question : Can I communicate from the browser to others app in real time (websocket based) with my current architecture and if yes, how ?
On the Azure WebPubSub Documentation Page there are no examples of what I try to achieve. Same thing searching on the internet.
A solution using an Express.js server linked to the app, being the could be used as the middleman between the browser app and c# app. But I want to avoid it if possible.
I just want to know if what I'm trying to do is possible.
Also, the app could be re-done in React.js so non-Angular specific answer are better.
The Web PubSub logstream sample:https://learn.microsoft.com/azure/azure-web-pubsub/tutorial-subprotocol?tabs=javascript sounds like a similar scenario.
Your AngualrJS Web App is similar to the logstream's web application, and it joins the stream group.
Your C# .Net 5.0 desktop application is similar to the logstream's message publisher application stream: https://learn.microsoft.com/azure/azure-web-pubsub/tutorial-subprotocol?tabs=csharp#publish-messages-from-client, which send messages to the stream group.

Need some hint on how to start porting my application

We have two applications, one called flexOS locally on "the server", and one called flexVisu remote on "the client". The first one is doing the job, collection data and such things.
Historically those two applications are able to communicate via TCP/IP sockets and a proprietary binary protocol.
Now we want to replace the client application flexVisu with a web page hosted on the IIS locally on the server. Every web browser on every device should be able to display these web page(s).
Firstly we experimented with an additional application (flexVisuWebServer) on the IIS side that basically hosted a web socket server and translated the json data from the client into binary data for the server and vice versa.
But this always requires a http connection and a wss connection to be open at the same time.
I don't know why, but I don't like the idea of using javascript on the client to handle all the data processing to display the server data.
I think that it would be much easier if I wrote an asp.Net c# application that handles the connection to "the server" via our proprietary TCP/IP protocol. That way no conversion of data between binary and json format must be done, and the web page itself can be also written in C#.
This approach much more resembles the current approach with flexVisu connecting directly to flexOS, the binary data is directly used to fill in Windows Forms controls.
What am I missing here?
Would the asp.Net application be able to connect to a tcp socket and use our own protocol?
[Edit: 2021-02-09 at 16:18 localtime]:
I managed to use our proprietary TCP/IP protocol to connect from the web server to the flexOS in the page_load of the asp.net web page.
So basically it should not be a problem to use the underlying library to read data directly from the flexOS.
OT: Should i post subsequent ASP.Net questions here too, or open some more questions?
We decided to follow this concept:
the webpage is using a websocket connection to our application flexVisuWebServer and this application uses our propietary TCP/IP protocoll to talk with flexOS.

Locate server on LAN in JavaScript

TL;DR
In Javascript, how do you to find the IP of all servers running a specified program on a specified port in the LAN?
Background
I'm writing a server in node.js that is supposed to connect users browsers as controllers to a common device on which a game is running. The browsers are running a web app based on html and Javascript. The connection is based on socket.io.
I'd like for the web app to be able to find all available instances of this server in the LAN in order to create a server list for the user to choose from.
Is there a way to make the server discoverable by the web app on the local network in Javascript, and in that case: how?
Ideas
Have the server broadcast its IP to all devices on the LAN and have the web app listen for these messages (No idea how to do this without node on the client)
Connect to every IP on the network and see if the connection is successful. (Does not seem feasible)
Scan every IP on the network and connect only to those where the port is open. (Once again, no idea how to do this without node on the client and does not seeem feasible either.)
EDIT
The server is supposed to be portable and work independently, without any central system backing it up or providing matchmaking for clients. It is a LAN only server and should work even without internet access.
There is no way for you do this. Sorry. Since there is no exposure to UDP on client-side JavaScript, broadcasting is out of question. Any attempt on massive scanning will quickly raise flags on network monitoring software. You have to use a known address.

How to convert node.js application into cordova

we built a node.js application for desktop and tablet. It's completely web based application. Now I am planning to implement same application as native app in android using Apache cordova.
Under project directory, we have node_modules,public,.... all client side files are in public folder. When I invoke URL in browser, from client side I am making API call to check whether user already logged or not. like this we are making API calls to my server.
As per my understanding,native app is nothing but we are storing all the client side files into device. whenever user open app will load client side files and as per work flow it will make API calls.
Theoretically I understand that much.
where I stuck :
In desktop app , I used to make API calls with URL like /api/web/shared/reject/, here we don't need to mention server address like localhost:8080/api/web/shared/reject/ that everything browser will take care. This same thing how can I make it work in cordova applications.
How cordova will know whether it is localhost or something else...
Regarding this, I Goggled but I didn't find any tutorials.
can anyone suggest me the way.
Basically, is a concept problem.
Node.js is a technology specialised in backend and some of usages like extend some services/functions, etc.
When you talk of a localhost:8080 you are talking that your node.js implementation should be in a server (Amazon, Azure, your own server, nodejitsu, etc), and the public pages or the pages that the client should consume will be added into phonegap, specifically in your www directory and the references for localhost:8080 should be changed for your server (Amazon, your own server, nodejitsu, etc), and the files on your www directory could have references (via GET or POST to retrieve the data from the server. Remember, the Crossdomain problem doesn't happens on phonegap (maybe in a local enviroment should occur).
And Phonegap is a framework to develop front-end with HTML5, jquery, CSS3 and other releated technologies.
For your specific case the node_modules should be installed in the server too, not on the phonegap project.

Categories

Resources