Connecting WebSockets from browser to other applications - javascript

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.

Related

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.

How to use a Node.js web server with an Apache Cordova Application

I have designed an Apache Cordova Application that uses a Node.js web server to pull data from a web API and allows the Javascript based project to use data pulled from this API.
Is there a way that I can use this Node web server across an iphone implementation of this cordova application? I am currently testing the application by pulling data from the website's API, hosting in on a node (ex. localhost:3000) and then pulling the data from that address in the JS file in my project.
How can I implement this server so that it can be used on an iOS mobile device?
If you want to host your Node server somewhere so that devices can see it on a network, then Amazon AWS Elastic Beanstalk has an easy solution for that - just upload your Node project in a Zip file and they manage the server environment for you.
There's several other options out there depending on your needs, for example Heroku may be a good alternative.

Communicate between a browser application and .net Windows application

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

Accessing DynamoDB from client side using javascript?

I am developing an HTML5 mobile application which I am planning to port to Android also using Phonegap. I want to use AWS DynamoDB for storing my users data. I know that amazon has a http api but it is too complicated. Some of my queries are
If I use the HTTP api, wouldn't it expose my credentials? (Same qquery for dynode)
What are the alternatives? I have a EC2 instance so hosting a server is not a problem.
I would appreciate your suggestions on this.
If you connect directly from your phone application, to dynamodb, you will risk exposing your credentials.
The general way to handle this is to have a json REST api through which the phone application can authenticate and make requests to the datastore. Your application would communicate with this api.
In this case, each user would likely have its own authentication to your server application.

How to build xmpp over web sockets web chat application like gtalk

How to build xmpp over web sockets web chat application like gtalk using javascript+html or asp.net?
ıt accepts file transfer, video conferencing, private or group chatting. Multiple users and servers can communicate with each other.
If you want your chat system to work with google's gtalk, or If you want to create your own chat server and make private system you will need to implement xmpp on javascript,
follow the links that will help you
http://professionalxmpp.com/
https://github.com/maxpowel/jQuery-XMPP-plugin
There are two ways to achieve your goal:
You can build your own chat solution from scratch (build backend solution using XMPP XEPs, etc. and client-side app)
To make it easier for you, you can use a ready backend and SDK provided by some BaaS providers. In such way you can concentrate on building client-side solution and its UI while you already have a ready backend and a set of requests to connect to that backend and use it.
You can try ConnectyCube since it has both chat and video chat. For video chat they have two options: WebRTC peer-to-peer solution and SFU based one.

Categories

Resources