python - the idea behind chat website -


i've been learning python socket, http request/reponse handling these days, i'm still novice server programming, have question regarding fundamental idea behind chatting website.

in chatting website, omegle or facebook's chat, how 2 guys talk each other? sockets on own computers directly connect each other, or... guy send message web server, , server send message guy b, , vice versa?

because in first scenario, both users can retrieve each other's ip, , in second scenario, since connecting server, can not.. right?

thanks lot clear confusion me, i'm new , appreciate guys!

usually both connect server.

there few reasons way. example, imagine want users see last 10 messages of conversation. who's going store info? 1 client? both? happens if use more 1 pc/device? happens if 1 of them offline? well, have send messages server, way server have conversation history stored, available.

another reason, imagine 1 user offline. if user offline can't contact him. can't connect. have send messages server, , server notify user once online.
going need connection server (storing common info, providing offline messages, keeping track of active users...).

there reason, if want 2 users connect directly, need 1 of them start server listening on (public ip):port, , let other connect against ip:port. well, problem. if use clients->server model don't have worry that, because can open port in server easily, all, without routers , nat in between.


Comments