Server - Client comunication - javascript

considering websoket connections ex. (javascript client -> php / asp server) or asynchronous ajax requests, I was looking for reverse communication: server-> client, to get a certain response from the server without making the request. Assuming a batch process that runs on server, which communicates the presence of a data ready to the client when the desired data has been processed. Does such architecture exist?

Related

How can i call my resteasy service remotely?

I have implemented a resteasy service runs on Wildfly server, which communicates with a mysql database. The frontend runs on an apache server and sends xhr requests to the rest service via javascript. Through port mapping I was able to call the javascript frontend in remote, but not to call the backend. Any solution?

How can my server know which client to respond to after a separate domain redirect?

For example,
I go to a webpage (webpage W), and now I am the client.
Server A is the server associated with the webpage, that I coded and have control over (coded in Java)
Server B is a server on a completely different domain, and I do not have control over it. It is running its own webpage.
Client sends Javascript AJAX request to server A, and server A responds with an OK. The code continues, and then the code redirects the page to server B's webpage. Now the current page is server B's webpage.
After whatever needs to be done on server B's webpage, server B uses HTTP to call back to server A.
Now, server A has received the request, and the controller needs to redirect the client back to webpage W. However, the HTTP request came from server B, not the client. I couldn't just tell the request to redirect to webpage W because the request didn't come from the client.
The HTTP request comes from server B, and server A catches it, but then how does server A know the original client (me) to redirect to webpage W?
In more vague terms, is there a way for my server to find the original client session after a redirect to another domain?
a real use-case may prove useful here however as I understand your question
Client (browser) loads webpage from your server.
Then the client makes another request to your server via ajax.
At some point you describe a redirect to server B. It is unclear if this is done via a location header in the ajax response or if after receiving the ajax response javascript is used on the client to then redirect the page to server B.
I'm going to assume it is client side javascript beings you said that server A responds to the ajax request with OK (implying 200, not 302 or 301)
So if the client is now looking at server B, and server B (not the client) makes a request to server A then it is a totally new session, all you know is what is sent to you. However you should reply to the request the same regardless of where it comes from.
for example, suppose you had an endpoint /foo .. the reply to /foo would be the same if it came from the client, or from server B .. you have no control over the client from server A.

Node.js server, importing and exporting data to and from client

I am making a node.js server and I have the code to get the server running. However, I am not sure how to get data from the client into to database. This is a game I am working on which I want to make multiplayer so I am new to node.js. Every player has a different picture on their screen and I am using javascript to draw on a canvas in my html file. How do I get information from the player and then query that to then give them an output to draw on their screen.
Thank you the sooner this can be answered the better
A browser client can do one of three things with a server.
It can request a new web page thus changing the active page in the browser (probably not what you're asking for).
It can send an ajax call to the server and receive a response from the server. An ajax call can either be used just to send information to the server or it can be used to get information from the server and then display that information to the user by changing the currently displayed web page.
You can create a lasting webSocket connection to the server. After the webSocket connection is created, then the server can send the client new data or requests or the client can send the server data or requests. Data or requests can be sent either way.
If you just want to send from the web page to the server so that the server can store something in the database, then you would likely use the 2nd option (an Ajax call). You would create a route in your node.js server (e.g. a specific URL for this Ajax call) and then from your client, you would make an Ajax request to that specific URL. You can also send data or parameters to the server with the Ajax request.

Maintain a backend connection on NodeJS across page requests?

I'm making connections via thrift (node-thrift) to a backend server to make api calls, but the communication is bidirectional (push/pull) to NodeJS.
While a user is browsing around different URLs, and Node is churning out jade templates and javascript files via Connect/Express routes, how do I maintain the connection to the backend server, and output (as an example) the connection status as part of the rendered jade output?
I have the connection object, but what do I do with it?
Sockets and port communication is generally a new area for me, so any help would be appreciated.
Keep in mind that backend server is not communicating to the web browser as the client, but rather the NodeJS server as the client.
(updated after discussion in comments)
So it looks like thrift is TCP-based which means the node client is going to keep the connection to your thrift API server open. This is entirely independent of what your node/express app server is doing with the browser clients. So if you keep a reference to your thrift client available to all requests, by attaching it to the app object for example, you should be able to determine it's current status and include that information in HTTP responses to the browser. There's not going to be any automatic coordination or association of any kind between your express app server handling browser HTTP requests and your thrift client making RPC calls to the API server. If you want coordination, you need to code that explicitly, but sending an HTTP response to a browser isn't going to automatically close your thrift TCP connection to the thrift RPC server (and same story vice versa).

How activemq works

I read on the ActiveMQ official page how it works, but could not understand the whole scenario how request and response is going on.
As per my understanding now, if I have a servelet on server and JavaScript as client using amq.js, then
JavaScript sends a poll request to server.
Server starts a thread and checks for data to be sent as response.
If data is not available at that time, server waits till there is any data.
Server sends the data when available and then the connection breaks.
Client receives the data and again send the poll request.
In this way the client request is parked at the server till the data is received.
Is this understanding correct and possible?
If yes, how the request is parked at the server?
Thanks.
Yes, you understand it correctly. But with the restriction that the request will be on hold for 30 seconds, then it times out (default).
The request is parked at the server using Jetty Continuations, as Jetty is the servlet container in ActiveMQ.
Since ActiveMQ, java side, can be setup with asynchronous listeners, there does not need to be on thread blocked for the entire poll.

Categories