Skip to content

Instantly share code, notes, and snippets.

@kwhinnery
Created September 21, 2016 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwhinnery/08b9da6f7ff6c2e70909425a9e0a50b8 to your computer and use it in GitHub Desktop.
Save kwhinnery/08b9da6f7ff6c2e70909425a9e0a50b8 to your computer and use it in GitHub Desktop.
html
head
title Socket.io Example
body
h1(class="something") Socket.io Example
input#msg(type="text")
button send message
#messages
script(src="/socket.io/socket.io.js")
script(src="//ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js")
script.
var socket = io();
$('button').on('click', function() {
socket.emit('message', $('#msg').val());
});
socket.on('message', function(msg) {
var $span = $('<div>');
$span.text(msg);
$('#messages').append($span);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment