Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js socket.emit

const socket = io('ws://localhost:3000');
socket.on('connect', () => {  
  // either with send()  
  socket.send('Hello!');
  // or with emit() and custom event names  
  socket.emit('salutations', 'Hello!', { 'mr': 'john' }, Uint8Array.from([1, 2, 3, 4]));});
// handle the event sent with socket.send()
socket.on('message', data => {
  console.log(data);
});
// handle the event sent with socket.emit()
socket.on('greetings', (elem1, elem2, elem3) => {
  console.log(elem1, elem2, elem3);
});
Comment

socket emit to

io.to(socketid).emit('message', 'whatever');
Comment

PREVIOUS NEXT
Code Example
Javascript :: what is new set in javascript 
Javascript :: gym open ai 
Javascript :: js check string is date 
Javascript :: Find the longest string from a given array 
Javascript :: how to skip the execution or for loop using continue js 
Javascript :: javascript the event loop 
Javascript :: splice js 
Javascript :: greater than x but less than y javascript 
Javascript :: @angular-devkit/build-angular <error 
Javascript :: nested include sequelize 
Javascript :: async await javascript push 
Javascript :: include hover in style jsx 
Javascript :: jquery call a class 
Javascript :: axios interceptors 
Javascript :: appearing datepicker behind the modal 
Javascript :: set javascript 
Javascript :: attr.disabled not working in angular 
Javascript :: javascript functions 
Javascript :: Modal dismiss react native by click outside 
Javascript :: js error handling 
Javascript :: array limit js 
Javascript :: mongoose in nodem js 
Javascript :: What is array.push in javascript 
Javascript :: how to set asp radio button value to checked as per retrieve record in javascript 
Javascript :: how to use fetch in gatsby 
Javascript :: create shadow root 
Javascript :: js element on mouse over 
Javascript :: alternative to setinterval 
Javascript :: mongodb findoneandupdate return new document 
Javascript :: render partial in js.erb 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =