Skip to content

Instantly share code, notes, and snippets.

@KazChe
Created March 27, 2014 04:04
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 KazChe/9799976 to your computer and use it in GitHub Desktop.
Save KazChe/9799976 to your computer and use it in GitHub Desktop.
blog_socketio_client_js
// This is important, the io.connect has to point where socket server
// is running - simple but took me while to connect the periods/dots/slashes...it's weekend, what am I doing?
var socket = io.connect('http://localhost:8111');
// image related socket
socket.on('user image', function(m){
// $('#imageReceivedMessage').text("> "+m);
$('#imageSentFromServer').attr('src', m);
});
socket.on('connect', function(id){
$('#status').text('Connected');
});
socket.on('setID', function(myID) {
console.log('receive id: ' + myID)
$('#IDReceivedMessage').text(myID)
});
socket.on('message', function(m){
$('#message').text("> "+m);
});
socket.on('disconnect', function(){
$('#status').text('Disconnected');
});
socket.on('customEvent', function(message) {
$('#customEvent').text(">> "+message['time']);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment