I'm building Socket.IO's example chat project (with some modifications) and I've been trying to get people to connect with both localhost:3000
and 127.0.0.1:3000
, but neither are working. Am I missing something? (If there's a blatantly obvious problem, sorry. I suck with networking.)
index.js:
var app=require('express')();
var http=require('http').Server(app);
var io=require('socket.io')(http);
var chalk=require('chalk');
var online=0;
var prt=process.argv[2]===undefined?3000:process.argv[2];
process.stdin.on('data',function(){
var str=String(process.stdin.read());
if(str.search("!quit")){
io.emit('chat message','Console: stopping server.');
process.exit();
}
});
app.get('/',function(req,res){
res.sendFile(__dirname+'/index.html');
});
io.on('connection',function(socket){
online++;
console.log(chalk.green('joined |',chalk.cyan(online),'online'));
socket.on('chat message',function(msg){
io.emit('chat message',msg);
console.log(chalk.magenta('message |',msg));
});
socket.on('disconnect',function(){
online--;
console.log(chalk.red('left |',chalk.cyan(online),'online'));
});
});
http.listen(prt,function(){
console.log(chalk.yellow('SIOChat listening on',chalk.cyan(prt)));
});
index.html (omitted css for readability):
<html>
<head>
<title>SIOChat</title>
</head>
<body>
<ul id='messages'></ul>
<form action=''>
<input id='m' autocomplete='off'/><button>Send</button>
</form>
<script src='https://cdn.socket.io/socket.io-1.2.0.js'></script>
<script src='http://code.jquery.com/jquery-1.11.1.js'></script>
<script>
var socket=io();
var name=prompt('Enter a nickname','Guest');
$('form').submit(function(){
socket.emit('chat message',name+': '+$('#m').val());
$('#m').val('');
return false;
});
socket.on('chat message',function(msg){
$('#messages').append($('<li>').text(msg));
});
</script>
</body>
</html>
I am using jQuery UI for information display on desktops in tabs and have so for some time. I have added Responsive Tabs to Accordion to show the same information in accordion tabs for tablets and ...
I am using jQuery UI for information display on desktops in tabs and have so for some time. I have added Responsive Tabs to Accordion to show the same information in accordion tabs for tablets and ...
I am attempting to disable a button using an external JavaScript - activated by a submit button <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
I am attempting to disable a button using an external JavaScript - activated by a submit button <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
I'm new to HTML (just started learning at school) and I have a small question about classes and the ability to filter them. Basicially, I'm working on a page of football fixtures, which will look as ...
I'm new to HTML (just started learning at school) and I have a small question about classes and the ability to filter them. Basicially, I'm working on a page of football fixtures, which will look as ...
So, I'm not sure if I should've structured my app different or if I'm doing something fundamentally wrong. I'm a bit confused, but let's explain first things first. In the first navigation level, ...
So, I'm not sure if I should've structured my app different or if I'm doing something fundamentally wrong. I'm a bit confused, but let's explain first things first. In the first navigation level, ...