How to store an ID on the client side of an HTTP server-client architecture - http

The case is, I have an HTTP server and client code. The server generates and stores an ID for every client that connected. The client must then store the given ID so that when it reconnects to the server, the server can recognize the client, but the catch is the user of the computer must not change the client so the id must be stored somewhere the user can't access.

Related

How are Server-Sent Events supposed to be used in a "update list" scenario?

What I want to achieve is the following:
There is a list of things and the server wants to notify the client about changes to that list.
Which of the following setups are recommended and why:
I send an SSE request from the client to the server and the server sends updates of the list in an event. The server doesn't close the connection, it is closed when client leaves the page the list is on.
I send an SSE request from the client to server. The server sends an event when the list is updated, then closed the connection. The client then (after processing the event) sends a new request to the server, waiting for another event from the server.

How to queue APIs requests with RabbitMQ

I would like to queue requests made by mobile application that uses API to send some data to the server.
The scenario for now is like this:
Mobile app sends a request with some data
I need to get the data, validate it (a few DB queries) and save to a few tables in DB.
I need to return OK response to mobile app or bad request with erros list in case the validation has failed.
Now if I have 1 000 requests like this in 3 seconds my server will collapse.
I would like to use RabbitMQ to queue those requests. But what should I do with a response? I cannot send OK after RabbitMQ has received the message cause I don't know if the validation will pass. So mobile app will wait until RabbitMQ message will be properly consumed?
This could be a solution to your problem:
The client sends a request
The server queues the request and generate a unique identifier that belongs to the queued request, and then sends a response containing the generated identifier with 202 (Accepted) status code that means the request has been queued or submitted on the server but there is no response yet.
The client subscribes to the generated identifier on a message broker
After a queued request finished on the server it will publish a response to the message broker based on the generated identifier for a request
The client will receive published response on the subscribing identifier
Tips:
I use EMQTT for the message broker. Another option would be Rabbitmq MQTT plugin

Does the communication channel breaks in between client and server if we introduce a load balancer in SignalR?

I am new to SignalR and I have a question on SignalR communication when we introduce a load balancer.
Lets assume we want to execute a void method on server side which receives some data as a parameter from client. Server takes that data and processes further. Lets say after processing for a while, it identifies that it has to send the notification back to client.
Case 1(Between client and server): Client calls void method on server side(Hub) by passing some data. Connection gets disconnected. Server processes the client data further. When it identifies that it has to push the notification back to client, it recreates the connection and pushes back the data to client.
Case 2(Between client and server with load balancer in between): How does the above scenario(Case 1) work here?. When server sends the push notification back to load balancer after processing client data, how does it know to which client it has to send the notification back?
You should read the scaleout docs. Short version: messages get sent to all servers, so if the client reconnects (it's not the server that establishes the connection!) before the connection times out , it will get the message.
Quote from the docs:
The cursor mechanism works even if a client is routed to a different
server on reconnect. The backplane is aware of all the servers, and it
doesn’t matter which server a client connects to.

Best way to send data to a non-browser client behind NAT and firewalls?

Here is the scenario:
Client #1 put some info to the server (using an HTTP request)
Server keeps that info and wait for client #2 to put his info too. Time between client #1 and client #2 calls can be from a couple of seconds to several hours.
When client #2 put his info to server, server return client #1 infos to client #2 through the HTTP request.
Server then need to return the client #2 infos to client #1.
How can I return client #2 infos to client #1, assuming that client #1 cannot be directly reached (NAT, firewall) and that the time between the two calls can be very long?
I would like to avoid client #1 to regularly poke the server... Clients are not using a web browser to connect to the server but a custom application where we have total control
The client will have to poke the server periodically, if the client closes its connection anytime between steps 1 and 4. Otherwise, let the client keep its initial connection open waiting for a server-side push of the data, even if it takes hours, then close the connection once the data arrives.

How can a server know which session belongs to which client?

In my office we have multiple computers and when we check from a remote server what is the IP of each computer, since they all come out of the same router, I get the same IP.
This started me thinking about how the server knows what session belongs to which client?
What identifies one computer from another in the eyes of the server when the IP address is similar?
Thanks everyone!
Server sends a cookie to the user with a session id. This session id identifies the user to the server. ASP.NET can also append the session id to the query string if cookies are turned off.
http://msdn.microsoft.com/en-us/magazine/cc163730.aspx
On each request made to server by the client a TCP connection is made with has common IP address in your case but different port and each client is differentiated on the bases of port to send the response back to the client. You can read more about TCP connections over here.
If you are talking about HTTP session then they use cookies / query string in url to identifiy session, you can read more over here.
Session Identifiers
Sessions are identified by a unique identifier that can be read by
using the SessionID property. When session state is enabled for an
ASP.NET application, each request for a page in the application is
examined for a SessionID value sent from the browser. If no SessionID
value is supplied, ASP.NET starts a new session and the SessionID
value for that session is sent to the browser with the response. By
default, SessionID values are stored in a cookie. However, you can
also configure the application to store SessionID values in the URL
for a "cookieless" session, reference.

Resources