socket.io error

Raggaer

Godly Member
Joined
Jul 25, 2012
Messages
1,556
Best answers
8
Reaction score
894
Location
Spain
Not sure if here anyone can help me but using socket.io websockets Im getting confused with

Server.js

Code:
var app = require('http').createServer(handler)
  , io = require('socket.io').listen(app)
  , fs = require('fs')

app.listen(88);

var texto = 'AAA';

function handler (req, res) {
  fs.readFile(__dirname + '/index.html',
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }

    res.writeHead(200);
    res.end(data);
  });
}

io.sockets.on('connection', function (socket) {

  socket.on('Text', function(data) {

    socket.emit('add', data);

  });

  socket.on('disconnect', function () {

    io.sockets.emit(' USER DISCONNECT ');

    });

});
Client.html

Code:
<html>
<body>
<script src="/socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
  var socket = io.connect('http://localhost');

  socket.on('connect', function () { 

    $('#button').click(function() {

    	var addtext = $('#text').val();

    	socket.emit('Text', addtext);


    });

    socket.on('add', function(data) {

    	socket.broadcast.emit('AAA');

    });

  });
</script>
</script>
<textarea id="aqui"></textarea><br />
<input type="text" name="text" id="text"><input type="button" name="button" id="button" value="Enviar mensaje">
</body>
</html>
It seems that the socket 'add' never gets to the client ! anyhelp..
Thanks

- - - Updated - - -

Well i fixed it, will post it here if someone ever runs this issue

New server.js

Code:
var app = require('express')()
  , server = require('http').createServer(app)
  , io = require('socket.io').listen(server);

server.listen(88);

app.get('/', function (req, res) {
  res.sendfile(__dirname + '/index.html');
});
 
Top