i am learning socket programming and Django web developing. As what i know socket is used for the communication between client and server. Dose this mean that when using and submitting Form in Django, there will be a socket created and submitted to the server?
Dose this mean that when using and submitting Form in Django, there will be a socket created and submitted to the server?
The short answer: yes.
Your terminology is a bit off: a socket isn't "submitted" to the server. A socket is used for sending data to, and receiving data from, somewhere else.
The longer answer is of course much more complicated. The longest answer fills textbooks.
There are a few layers to peel off here.
HTML forms are transmitted to the server using HTTP.
HTTP is an application-layer protocol which is built on top of TCP.
TCP is a transport layer protocol (built, of course, on something else).
So, in the simplest case*, when the form is submitted, the browser sends an HTTP POST to the server. The browser's HTTP implementation will open a TCP connection to the server, and that's a socket. Through that socket, the HTTP message is transmitted, and the server's response is received.
So a socket is a much, much lower-level construct than an HTML form.
From Wikipedia, here's a full view of the layers of the networking stack:
If you find this stuff interesting, I recommend taking a course on computer networking.
* No Connection: Keep-alive, for instance.
The socket is created but not submitted to the server. Django is for HTTP server (port 80 and some other custom used ones). It is a library built around sockets listening/connecting to said port and with extra added features needed in Web development.
Socket programming is more general since it is lower level than Django and it allows using any port number you desire.
On the ISO OSI stack Django stays on level 7 while socket programming is at level 4.
Sockets are just one method of communicating between client and server, but not the method Django is using when processing a form submission. It is most likely sending a HTTP POST request with parameters that the server listens for.
Related
I'm thinking of writing an application that when running keeps track of all the websites I visit and connections I make.
Basically like a browser history, but I want to do it in a way that utilizes network concepts.
I only have a rudimentary understanding of Http, but would I be able to listen in on Http get requests from the browser and automatically pull information whenever a request is made? If anyone can give me a suggestion or outline of how this can be done, so I can research on implementing it, it would be very helpful! I'm thinking of implementing it in python, and my operating system is Ubuntu
Thank you very much.
You could do that by implementing a proxy.
In your case, basically, an agent that sits between your browser and internet. The proxy receive the request from the client, then, send it to the remote server, the remote server may reply to you and you'll have to send the server response back to the client.
To retrieve the informations you are wanting, reading the Http rfc will be helpful.
I have a web application running Django and a separate websocket server. Both using single Django model. When Django make changes to the model, I want Django to notify websocket server about this changes.
Obviously, the way of simply connecting to websocket server and sending one message is looking bad due to increasing server load through connecting/disconnecting clients for each user form submit and due to websocket concept in general.
I've heard about solutions using AMQP server for similar purposes. The question is: is that a good idea, or there are better solutions in my case?
Have a look at https://github.com/jrief/django-websocket-redis
Documentation: http://django-websocket-redis.readthedocs.org/en/latest/
I have an existing chat socket server built on top of twisted's NetstringReceiver class. There exist Android/iOS clients that work with it fine. Apparently web sockets use a different protocol and so it is unable to connect to my server.
Does a different chat server need to be written to support web sockets?
“Yes.”
If you'd like a more thorough answer, you'll have to include more information in your question.
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.
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.