Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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