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 :: javascript for...of with Arrays 
Javascript :: react-bootstrap problem-install new version 
Javascript :: auto scroll to view react-native 
Javascript :: ngmodel component angular 
Javascript :: js map key value 
Javascript :: how to use useref hook in react 
Javascript :: tableau js 
Javascript :: faker.js 
Javascript :: vue displaying a this.length 
Javascript :: html anchor tag javascript confirm 
Javascript :: keycloak api get an user by exact username 
Javascript :: how to handle error js 
Javascript :: select parent of elemt 
Javascript :: sequelize include twice 
Javascript :: fetch data with axios in reactjs 
Javascript :: javascript optional add object key 
Javascript :: vue js app component 
Javascript :: angular Failed to make request to https://www.gstatic.com/firebasejs/releases.json 
Javascript :: get text selected 
Javascript :: get 2nd td of tr 
Javascript :: jquery selectors attribute ends with 
Javascript :: razorpay node sdk 
Javascript :: javascript valueOf() Method 
Javascript :: js stringify 
Javascript :: HOW TO ADD INDEXES TO EXISTING COLLECTIONS mongodb 
Javascript :: add an object to an array mongosse 
Javascript :: fetch method post handing the post add on php 
Javascript :: using template literals to create html 
Javascript :: moment.set 
Javascript :: Laravel JSON Where Query 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =