Does websocket only broadcasts the data to all clients connected instead of sending to a particular client?

StackOverflow https://stackoverflow.com/questions/13967051

Pergunta

I am new to Websockets. While reading about websockets, I am not been able to find answers to some of my doubts. I would like if someone clarifies it.

  1. Does websocket only broadcasts the data to all clients connected instead of sending to a particular client? Whatever example (mainly chat apps) I tried they sends data to all the clients. Is it possible to alter this?

  2. How it works on clients located on NAT (behind router).

  3. Since client server connection will always remain open, how will it affect server performance for large number of connections?

  4. Since I want all my clients to get real time updates, it is required to connect all my clients to server, so how should I handele the client connection limit?

NOTE:- My client is not a Web browser but a desktop application.

Foi útil?

Solução

  1. No, websocket is not only for broadcasting. You send messages to specific clients, when you broadcast you just send the same message to all connected clients, but you can send different messages to different clients, for example a game session.

  2. The clients connect to the server and initialise the connections, so NAT is not a problem.

  3. It's good to use a scalable server, e.g. an event driven server (e.g. Node.js) that doesn't use a seperate thread for each connection, or an erlang server with lightweight processes (a good choice for a game server).

  4. This should not be a problem if you use a good server OS (e.g. Linux), but may be a limitation if your server uses a desktop version of Windows (e.g. may be limited to 200 connections).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top