Socket.io Flashcards

1
Q

What is socket.io

A

Socket.IO enables real-time, bidirectional and event-based communication. It creates a persistent connection between client and server

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

full-duplex communication

A

Bi-diretional communitcation where the server can initiate communication with the client and vica versa.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which npm library allows us to work with socket.io

A

npm i socket.io

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to add socket.io to the a client?

A

In the html file add the following scripts to the body:

then in the public directory create a chat.js file with the following:

io();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to setup the server to work with sockets?

A
  1. setup an express server

const app = express();

  1. Manually create an http server outside of express

const server = http.createServer(app);

  1. Pass the raw http server into socket.io

const io = socketio(server);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Difference between io.emit, socket.broadcast.emit and socket.emit?

A

socket.emit emits an event to a single connection, while io emits an event to every single connection. broadcast.emit sends a message to all connections except for the one that triggers it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly