django save websocket to redis without closing it - python

Is there a way to keep websocket open using redis for future use ?
I need my django server to communicate with a websocket backend service on behalf of the client.
It means that I need to save the websocket open between multiple http requests of the client.
can I use redis for this purpose or is there any other way to do so ?
Thanks.

Related

Best practice to handle passwords/keys in python

I am developing a client and a server in python. The client connects to the server and send requests for the server to perform specific tasks. In one of the tasks the server needs to connect to a ssh server using a private key. Is there any good way to store this private key? Should it be stored in the client or in the server? If stored in the client, what would be the safe way to send it to the server when needed? I don't really want to have the need to type a password in the client everytime.
Thanks.

How to let server send the message first in GRPC using python

Hi i am new to GRPC and i want to send one message from server to client first. I understood how to implement client sending a message and getting response from server. But i wanna try how server could initiate a message to connected clients. How could i do that?
Short answer: you can't
gRPC is a request-response framework based on HTTP2. Just as you cannot make a website that initiates a connection to a browser, you cannot make a gRPC service initiating a connection to the client. How would the service even know who to talk to?
A solution could be to open a gRPC server on the client. This way both the client and the server can accept connections from one another.

Dealing with HTTP and websocket connections on the backend

I am working on a game I want to support over iOS/Android/Browser and thinking Websockets is what I want to use for the communication. I use python and so found that I should be using Tornado.
I am trying to understand websockets a little better and their integration in browsers.
Will the messages over the websocket connection also contain the HTTP cookies for the connection? If not can I send it?
How is the HTTP connection for the web page linked to the websocket connection? I mean how will I know they are coming from the same webapp on the server side?
The Tornado wiki page says in the performance section that Tornado can be set up with nginx as the front end. How does that work? I thought Tornado and nginx have to be running on separate machines since both listen on port 80 and also because nginx does not understand WS protocol. What am I missing?
Also it will be great if someone can point me to any resources I can read up on about either Tornado or websocket that could help me.
The websocket is setup by sending an ordinary http request to the server, this request will contain all the stored cookies for the domain. If you do a native implementation for e.g. Android you can use libraries like Autobahn|Android, the API allows you to set cookies for the websocket handshake.
You can set a cookie when first loading the page to maintain a session identifier.
In that scenario they would be running 4 Tornado instances (on different ports, but not port 80) and Nginx on port 80 as a load-balancer, spreading the incoming client requests to the Tornado instances, see running Tornado and Nginx on same server for a configuration example. Recent versions of Nginx does support websockets, see e.g nginx + python + websockets.

Push notifications from web server to desktop app in python

I have a service with users (in django) and desktop client for this srevice (on wxpython). I need to send notifications from server to desktop app for specific user.
What I can use for it?
Thank you!
I don't know wxPython, but if you want to use long-polling, comet or another technique based on HTTP protocol, then you need to write HTTP client or use any network framework.
For example Twisted.
Make connection to your django server and send data through TCP transport using HTTP protocol.

How to maintain server-initiated FTP connection between client requests in Python/Django?

I'm going to use ftplib to open up an FTP connection to an FTP server provided by the user. The client will be sending FTP commands to my django server via Ajax, which will then be forwarded to the FTP server the user provided. However, I'd like to not have to create a new FTP server connection every time the client sends an FTP command. In other words, I want to keep the FTP connection alive between requests by the client.
How would I do this? Would some sort of comet implementation be best? I was initially planning to use WebSockets until I discovered my host won't allow it. =\
You'll need to use a persistent connection framework as what you're trying to achieve really isn't what HTTP was meant for (in the sense that HTTP commands are stateless and independent), and thus not what Django is built for. There are a number of options, but since it seems you are in a restricted environment you'll need to do some research to determine what's best.
Switch hosts. Webfaction allows websockets with dedicated IP at around $20 per month.

Categories

Resources