NodeJS + socket.io: simple Client/Server example not working

后端 未结 3 1813
日久生厌
日久生厌 2020-12-28 10:31

I’m using NodeJS v0.4.8 and the latest Version of socket.io from

npm install socket.io

on Ubuntu:

Linux m

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-28 11:25

    Express 3.0 + Socket.io working example

    server ( app.js )

    var express = require('express');
        var app = express.createServer();
        var socket = require('socket.io');
        app.configure(function(){
            app.use(express.static(__dirname + '/'));
        });
        var server = app.listen(8081);
        var io = socket.listen(server);
        io.sockets.on('connection', function (socket) {
            console.log("connnect");
            socket.on('disconnect', function (socket) {
            console.log("disconnect");
         });
    }); 
    

    client ( index.html )

    
    
    

    you can fork the code using the link below https://github.com/sreekumar-kr/Expree3.0---Socket.IO

提交回复
热议问题