Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

socket cheatsheet

socket.emit('message', "this is a test"); //sending to sender-client only

socket.broadcast.emit('message', "this is a test"); //sending to all clients except sender

socket.broadcast.to('game').emit('message', 'nice game'); //sending to all clients in 'game' room(channel) except sender

socket.to('game').emit('message', 'enjoy the game'); //sending to sender client, only if they are in 'game' room(channel)

socket.broadcast.to(socketid).emit('message', 'for your eyes only'); //sending to individual socketid

io.emit('message', "this is a test"); //sending to all clients, include sender

io.in('game').emit('message', 'cool game'); //sending to all clients in 'game' room(channel), include sender

io.of('myNamespace').emit('message', 'gg'); //sending to all clients in namespace 'myNamespace', include sender

socket.emit(); //send to all connected clients

socket.broadcast.emit(); //send to all connected clients except the one that sent the message

socket.on(); //event listener, can be called on client to execute on server

io.sockets.socket(); //for emiting to specific clients

io.sockets.emit(); //send to all connected clients (same as socket.emit)

io.sockets.on() ; //initial connection from a client.
Comment

PREVIOUS NEXT
Code Example
Javascript :: delete a row in an array react hooks 
Javascript :: setinterval clearinterval querySelector until render 
Javascript :: create an array filled with 1 
Javascript :: Get characters between two characters 
Javascript :: how to print 1 to n numbers without using loop javascript 
Javascript :: get all keys of nested object json data javascript 
Javascript :: date change 
Javascript :: send data with next 
Javascript :: Get client or user ip address in react using axios 
Javascript :: adding values for metaboxes in wordpress 
Javascript :: javascript extrsct object 
Javascript :: pass props to svg 
Javascript :: Log Time from Date 
Javascript :: image support in node js chat app 
Javascript :: telegram web app js 
Javascript :: javascript values 
Javascript :: js plugin for drop down with images 
Javascript :: make a circle in javascript 
Javascript :: js tabbed data to array 
Javascript :: render(<App /); const linkElement = screen.getByText(/learn react/i); expect(linkElement).toBeInTheDocument(); 
Javascript :: how to bind multiple value in javascript 
Javascript :: react-select is unable to remove selected option after adding value props 
Javascript :: axios get request with body 
Javascript :: axios 401 unauthorized refresh token multipal request 
Javascript :: custom render contenful rich text rendering 
Javascript :: browser app get screen siwe 
Javascript :: can i pack a cross excutable file with nodejs 
Javascript :: React.createElement pass props 
Javascript :: copy Konva Transform object 
Javascript :: discord js ping command 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =