I am using websockets in javascript and python flask.
I have a websocket server to which i connect my webpage using javascript websockets. The "/" contains a form that contain the ip address of the websocket server, and "/connectToServer" route will establish a websocket connection with the server.
Now, I will have routes from this webpage like, /details, /profile. I need to use the same instance of the websocket in all my routes. How do i do it?
P.S. I do not intend to use the websocket client api in python. I need to do it in javascript only.
You would need something to make your page persistent.
Client-side libraries such as Angular or Vue (just two random examples) will do the job.
However you should look into a tutorial or something since its not very straightforward
Related
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.
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.
I have configured my Vert.x server built in Java to already handle HTTP connections properly, but I would like to add an additional layer of security through HTTPS. I use the standard fetch call to make POST requests to the server. I have searched through the Vert.x documentation already, but the only information I can find is if I use Vert.x as client code as well, but I would like to avoid that if possible. Is there a way to configure my client and server to work together to form a secure connection without having to build an encryption schema from scratch?
If I understood you correctly, you have but one VertX instance, without load balancer, and you would like to access it using HTTPS protocol.
It doesn't actually matter whether you access it through
When starting your VertX server, make sure you specify setSSL(true) and all the other arguments:
https://github.com/vert-x/vertx-examples/blob/master/src/raw/java/https/ServerExample.java#L39
is there a possibility to only use the frontend part of meteor and serve the files via a static vanish server?
I want to build a web app which uses an existing PHP REST API, but I lice the reactivity and the tempting of meteor, which I can get with the Session variable.
If there is a simple way to separate the frontend parts from the back so that I can easily serve them, would be awesome. Especially the web socket is not needed. Because there will be no after connection to the deliver server.
This cannot be done. For meteor to get live updates you need a connection to a server of some sort to relay the message down.
There are a couple of methods you could use, however
If you like the DOM reactivity and all the data is locally hosted/you would like to fetch it from php would like to use it in a static application something like angular or react could help you.
The other is you could use a deployed instance of an application & have it stored on a static/varnish server. But use DDP to have the server relay data. See http://arunoda.me/blog/hosting-meteor-apps-as-a-client.html
I have recently discovered HTML 5's support for the WebSocket protocol. I began idly experimenting with it and I decided to undertake a simple chat program project. For it, I'd like to be able write a WebSocket server and have it serve users inside of a blog post, using Google's Blogger website.
The server would be written in Javascript and would have all the code needed to send one person's "conversation line" to all other WebSocket connections connected to it. Later, I may implement "chatrooms" where each line is simply redirected to certain users.
My first question: would it be possible to create a Javascript-based WebSocket server? I've researched a bit, and it seems that all server implementations were in PHP or some server-side language similar to that. Would it be possible to write a WebSocket server with Javascript?
The server implementation would be inside of a webpage, so as long as the blog is up, the server would work as well. My blog can be found here. The client's code would be like this:
server = "http://imdmstromyf8imdcaptomysl.blogspot.com/post_that_handles_chat";
connection = new WebSocket (server);
The problem is, a WebSocket runs on its own protocol (ws:// or wss://), so changing "http://" to "wss://" would not work. Could I tunnel the WebSocket protocol through HTTP? If I did, I would probably have to use Ajax, but avoiding that is the reason I wanted a WebSocket chat program.
Blogger has a place where you can insert your own HTML; would it be possible to use PHP tags to delineate the code from HTML?
I would just like to know whether it's possible to do what I want, and if it is, some implementation tips or (even better) some example code to use.
"The server implementation would be inside of a webpage"
A server implementation is not in a web page. Not sure what you meant here. You may want to edit your question.
Node.js is library written in JavaScript for use on the server. Google this and you should find many ways of getting started on running a WebSockets. To connect to the client, you will be using JavaScript as well, which you should again select a library that supports web sockets.
Additionally, you will need to verify the client' Browser supports it.
You can look at browsers that support web sockets here
Here is a jQuery plugin for web sockets