I've been learning about Python socket, http request/reponse handling these days, I'm still very novice to server programming, I have a question regarding to the fundamental idea behind chatting website.
In chatting website, like Omegle or Facebook's chat, how do 2 guys talk to each other? Do sockets on their own computers directly connect to each other, OR... guy A send a message to the web server, and server send this message to guy B, and vice versa?
Because in the first scenario, both users can retrieve each other's IP, and in the second scenario, since you are connecting to a server, you can not.. right?
Thanks a lot to clear this confusion for me, I'm very new and I really appreciate any help from you guys!
Most chats will use a push notification system. It will keep track of people within a chat, and as it receives a new message to the chat, it will push it to all the people currently in it. This protects the users from seeing each other.
Usually they both connect to the server.
There are a few reasons to do it this way. For example, imagine you want your users to see the last 10 messages of a conversation. Who's going to store this info? One client? Both? What happens if they use more than one PC/device? What happens if one of them is offline? Well, you will have to send the messages to the server, this way the server will have the conversation history stored, always available.
Another reason, imagine that one user is offline. If the user is offline you can't do anything to contact him. You can't connect. So you will have to send messages to the server, and the server will notify the user once online.
So you are probably going to need a connection to the server (storing common info, providing offline messages, keeping track of active users...).
There is also another reason, if you want two users to connect directly, you need one of them to start a server listening on a (public IP):port, and let the other connect against that ip:port. Well, this is a problem. If you use the clients->server model you don't have to worry about that, because you can open a port in the server easily, for all, without routers and NAT in between.