Skip to content

Instantly share code, notes, and snippets.

@jokecamp jokecamp/client.html
Last active Aug 29, 2015

Embed
What would you like to do?
Working Socket.io 1.0 with path option
<!doctype html>
<html>
<head>
<title>Socket.IO chat</title>
</head>
<body>
<form action="">
<input type="input" id="m" /><button>Send</button>
</form>
<pre id="output"></pre>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script src="socket.io/socket.io.js"></script>
<script>
var socket = io('', { path: '/nfxplanner/socket.io/'});
socket.on('connection', function (data) {
console.log("connected to socket server");
});
socket.on('message', function(msg){
console.log('message recieved from server ' + msg);
$("#output").append(msg + "\n");
});
$('form').submit(function(){
var msg = $('#m').val() || "---";
console.log(socket);
socket.emit('message', "someone:" + msg);
console.log("message sent to server" + msg);
$('#m').val('');
return false;
});
</script>
</body>
</html>
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http, { serveClient: true, path: '/nfxplanner/socket.io/' });
app.get('/', function(req, res){
res.sendfile('index.html');
});
io.on('connection', function(socket){
console.log('a user connected!');
socket.on('disconnect', function(){
console.log('user disconnected!');
});
// emit incoming messages from client to Everyone!
socket.on('message', function(json){
io.emit('message', json);
});
});
http.listen(process.env.PORT || 8080, function(){
console.log('listening on ' + process.env.PORT || 8080);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.