Need some hint on how to start porting my application - javascript

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.

Related

Socket server on client side js?

I have node.js server, and I need to create dynamically updated web page with updating data. So, I thought that sockets are way to go.
But there's one problem. I need to send data from the server to client(to browser).
From my research, it is not really possible to create socket server with the client side JS. It is easy to do it the other way, but to send data only from server to client?
What would be best and easiest way to do that?
You create a webSocket or socket.io connection from your client to your server and your server is the webSocket or socket.io server. Once that connection is established, you can then freely send data either way across the connection, from client to server or from server to client.
This type of architecture is ideal for sending data from your server to a web page to dynamically update the web page as new data arrives.
webSocket is the base transport. socket.io is a layer on top of webSocket that adds a bunch of useful features such as auto-reconnect and structured messages. You can use either from a browser. webSocket support is built-in to the browser. If you want to use the additional features of socket.io, then you include the socket.io client library in your web page.
Here's a listing of some of the additional features socket.io offers over a plain webSocket: Moving from socket.io to raw websockets?.
I am not sure I have fully understood your question.
But, if I got it correctly, in order to have a "socket connection" you need to have two sides - a server and a client.
Use socket.io lib with a lightweight node.js server.
You can take a look at their docs + examples - will be very straight-forward.
If you still having trouble, write.

How to connect to MS-SQL database via JavaScript?

I understand this is not best practice but I am operating within a limited realm and, as far as I can tell, this is the only solution to this problem.
I am trying to connect to an MS-SQL database both to get data and to put data onto the database. I cannot seem to do it through JavaScript.
ActiveXObject is, from my understanding, now depreciated so that is not working, which eliminates every functional solution that I could find recommended in the past.
Please note: I am not a web developer and I have no access to any of the standard web development tools for this task.
This is the question has been asked multiple times in various forums - Can my client-side Javascript (running in a browser) connect to a database server and fetch data?
The short answer is - not recommended in general, not feasible without breaching security and without using outdated technologies. Let us dig into it.
It is possible to connect to remote database from a browser using outdated technologies
There are two pieces of technologies from Java and .Net worlds - Applet and ActiveX that run on the browser and can communicate to a remote database. The Java Applet is hardly used by anyone nowadays and browsers are stopping to support it. ActiveX is discontinued by Microsoft in their newer browser Edge. So, you have to enforce your target users to use old insecure browsers if you want to go with these options.
Do not use this.
Use databases embedded in the browser and sync with a remote database
You may use the database locally available in the browser and perform all read/write operations. Periodically sync this database with a remote one. Here are the options:
MongoDB and use change stream to sync with a remote MongoDB
PouchDB and sync with a remote CouchDB or even a MySQL database
Use this only for offline storage temporarily in the browser.
The traditional and secure approach to connect to a remote Database
Use a server-side technology to develop an app that your client-side code (Javascript, HTML) talks to. The app may provide RESTful APIs to interact from the client-side. Then the app that is running in a web server connects and interacts with the database. There are plenty of server-side technologies such as Java, PHP, Python, NodeJS (Javascript based), .Net, etc. to develop your server-side app.
Go with this option.
Well javascript is a client side scripting where as your database runs on a server. So firstly you cannot connect to a database for executing any query from client side i.e javascript and also you need to setup a server side service which can connect to the database and execute the query and give you the result at the client side. You can refer any client-server architecture for this on the web.

Having a web application listen for data without a server

For my job, I am researching a new means of accessing data from a web application created in either HTML or Javascript. The situation is that we have a proxy that takes data from a computer's serial port and broadcasts it as regular TCP data on the Local Host. We have web application that runs on the local system and we want it receive that data that is being broadcasted, however we want to implement this without creating a server to acquire said data.
So far I have been researching and googling for a solution but my search hasn't been fruitful. If there exists a means for a web application to acquire data being broadcasted from a proxy, I would like to know. Also we are running the web application locally from file:\ in IE11.
This stack overflow question is somewhat similar to our situation, however we cannot use Flash or Adobe Air: AS3 socket class connection with serproxy and sending data 

Connect to Secure Socket Server written in C++ with client written in JavaScript

What I want to achieve:
I have a linux server connected to network which runs a database. The database is not reachable from network. There is a software which acts as a middle layer between the server and client(s). The clients would access the database through this layer. This is required because:
There will be multiple users with different permissions.
I want a common API because the client software will be implemented to mobile platform, mostly for Android and as a webpage(this is where I want to use JavaScript) as well.
I don't want to expose the database directly to clients because I would be forced to store the database's login credentials in client's device.
The client software will be used only for data exchange and displaying the result to user. Any processing would be done in server.
The part which is not clear is the webpage. I could use PHP, but I want to make it like the Google Hangouts app in Gmail or the Facebook Messenger. The content which is fetched from database is displayed without reloading the page. Since I have't done anything like this in JavaScript, I don't know where to start, which libraries I should use.
Note that the communication between the client and the server would be done over secure sockets. The middle layer would be implemented in C++ using OpenSSL.
I would suggest to connect to the server using C++ with the system() command.

How to read serial port data from JavaScript

I connected an Arduino to my laptop using USB, and I can read the serial data using Processing.
Is there any way to get this data in real time into a local webbrowser? For example, a text field that shows the value from the serial port? It does not have to be connected to the internet.
The JavaScript version of Processing does not support the following code, which would have been the ideal solution.
The Processing code is:
myPort = new Serial(this, Serial.list()[0], 9600);
// read a byte from the serial port
int inByte = myPort.read();
// print it
println(inByte);
// now send this value somewhere...?
// ehm...
There is no way to directly access the local machine from the web browser. For security reasons browsers have very limited access to the machines resources.
To do this one option would be to write an extension for the browser of your choosing. Even though extensions also have a variety of limitations.
Option two would be to use local server to provide the functionality you need. Personally I recommend using node.js (it's light weight, fast and easy to implement). You can read/write serial data using https://github.com/rwaldron/johnny-five (as #kmas suggested) or https://github.com/voodootikigod/node-serialport and than you can use http://socket.io/ to create a simple service and connect to it though the browser. Socket.io uses WebSockets in modern browsers and works excepionally well for real-time connections.
I had a similar problem to solve. My Data acquisition system (DAQ) (like your arduino) relays data in HTTP, TCP, FTP, as well as serial. I had to capture it on the server and then send it to my webpage in real-time.
The hack I wrote uses nodejs at the server, and connects DAQ to the server using TCP sockets using the "net" module of nodejs and connects the server to the HTML page using socket.io.
The code and context can be found in "How to get sensor data over TCP/IP in nodejs?".
I use TCP as I wanted to transmit data over a long distance. You need to modify the socket protocol to serial.
For serial-to-TCP redirection, you may use bloom from sensorMonkey for Windows or their processing sketch for *nix/Mac OS.
if you want to send or receive serial data from Arduino to JavaScript in Processing code editor just go to Sketch -> Import Library -> Serial or just write import processing.serial.*;

Categories

Resources