Skip to content

Instantly share code, notes, and snippets.

@maddin77
Created March 13, 2016 11:23
Show Gist options
  • Save maddin77/c437b7a58489c7725a6f to your computer and use it in GitHub Desktop.
Save maddin77/c437b7a58489c7725a6f to your computer and use it in GitHub Desktop.
// pseudo-code
// wenn sich ein client verbindet
io.on("connection", function (socket) {
// irgendwas womit du den client eindeutig identifizieren kannst.
// benutzername, oder ne eindeute ID oder sowas
socket.username = eindeutigerBenutzername;
});
// irgendwo im code, wo du etwas an einen bestimmten nutzer schicken willst
// io.sockets.sockets ist ein array mit allen zur zeit verbundenen clients
// mit array.find kannst du dann einfach den client anhand username (oder was auch immer du oben genommen hast) suchen
const socket = io.sockets.sockets.find(function (socket) {
return socket.username === usernameDesBenutzersDenDuSuchst;
});
socket.emit("receiveOffer", blabla); // sendet das event nur an den einen Client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment