Tag: socket.io

Socket io 2.0.4找不到模块'./utf8'(Heroku)

我尝试安装并运行一个简单的应用程序与nodeJs套接字io和heroku.When我本地运行应用程序时,我没有得到任何错误,但是当我尝试在heroku上运行应用程序,我得到以下错误: Error: Cannot find module './utf8' at Function.Module._resolveFilename (module.js:489:15) at Function.Module._load (module.js:439:25) at Module.require (module.js:517:17) at require (internal/module.js:11:18) at Object.<anonymous> (/app/node_modules/engine.io-parser/lib/index.js:5:12) at Module._compile (module.js:573:30) at Object.Module._extensions..js (module.js:584:10) at Module.load (module.js:507:32) at tryModuleLoad (module.js:470:12) at Function.Module._load (module.js:462:3) at Module.require (module.js:517:17) at require (internal/module.js:11:18) at Object.<anonymous> (/app/node_modules/engine.io-parser/index.js:2:18) at Module._compile (module.js:573:30) at Object.Module._extensions..js (module.js:584:10) at Module.load (module.js:507:32) Ι使用heroku控制台在node_modules […]

为什么不能在断开连接时发送数据

我的应用程序是关于Web会议使用webrtc。 当客户端进行会议和聊天时,使用socket.io发送和接收事件的一切工作正常。 现在我想通知主页查看者关于当前房间和客户的数量,所以我也添加到这个页面的套接字 主页 var socket = io.connect('https://……………….'); socket.on('connect', function() { console.log('check 2', socket.connected); socket.emit('check','hello'); // works fine }); socket.on('numbers',function(data){ console.log(JSON.stringify(data)); // nothing as output }); socket.on('error', function (err) { console.log(err); }); 现在,如果客户端断开,服务器捕获断开事件,但不发生发射 服务器 io.on('connection' , function(socket){ ……… socket.on('disconnecting', function(){ socket.broadcast.emit('numbers','hello'); }); }); 我找不出什么问题。 主页面查看器是否与房间中的客户端不在同一个套接字中? 我想我在这里失去了一些重要的东西。 提前致谢

Socket.io开放了数百个连接

这是我的server.js代码: var express =require('express'), http = require('http'); var app= express(); var server = require('http').createServer(app); var io = require('socket.io').listen(server); users = []; connections = []; server.listen(process.env.Port || 3000); console.log('server running …') app.get('/', function(req, res) { res.sendFile(__dirname + '/index.html'); }); io.sockets.on('connection', function(socket){ connections.push(socket); console.log('Connected: %s sockets connected', connections.length); socket.on('disconnect',function(data){ users.splice(users.indexOf(socket.username),1); updateUsernames(); connections.splice(connections.indexOf(socket),1); console.log('Disconnected: %s sockets conected', connections.length); […]

表示应用程序和socket.io聊天在不同的端口?

我的问题很简单:如果我在快速应用程序的另一个端口上使用socket.io进行聊天,我是否遵循良好的实践或遵守标准? …说我的应用程序运行在4000所有路线( http://example.com:4000 : http://example.com:4000/contact 4000, http://example.com:4000 : http://example.com:4000/contact 4000/ http://example.com:4000/contact ,…),然后我创build“这”路线之一,但因为我的socket.io运行在3000现在应该是: http://example.com:3000/chatroom : http://example.com:3000/chatroom :3000/ http://example.com:3000/chatroom ,那么当然我为我的聊天客户端设置我的命名空间 var nsp = io.of('/chatroom'); 我做对了吗? 如果没有,请指向正确的方向。 谢谢!

失败:WebSocket在连接build立之前closures

所以当我在网站上启动js套接字时,我收到这个错误: 并在“websocketclosures….”一些错误后,网站将最终连接没有错误,但如果我再次刷新,那么我需要等待4-5或10个错误,直到它成功连接。 任何解决scheme,请? 我使用这个代码套接字服务器: var server = require('http').createServer(); var io = require('socket.io')(server); server.listen(3001); 前端代码: function connect() { if (!SOCKET) { var hash = getCookie('hash'); SOCKET = io('IP:3001'); SOCKET.on('connect', function(msg) { SOCKET.emit('hash', { hash: hash }); }); SOCKET.on('connect_error', function(msg) { $.notify('Connection lost!', 'success'); }); SOCKET.on('message', function(msg) { onMessage(msg); }); SOCKET.on('disconnect', function() { }); } else { […]

如何链接脚本并在生产服务器上连接socket.io?

我是新的所有相关的JavaScript programmimg,我有一个应用程序使用nodejs和socket.io本地(Mac)上完美的工作。 然而,我不知道如何链接的socket.io脚本,并不知道如何从应用程序连接到socket.io一次在我运行的服务器(Hostgator专用运行CentOS),我也使用claudflare。 我已经尝试了几种组合: 的index.php <script src="/socket.io/socket.io.js"></script> //or also <script src="socket.io/socket.io.js"></script> //console output is: Loading failed for the <script> with source “https://www.example.com/socket.io/socket.io.js”. <script src="my_ip_number/socket.io/socket.io.js"></script> //console output is: Loading failed for the <script> with source “https://www.example.com/my_ip_number/socket.io/socket.io.js”. <script src="my_ip_number:8080/socket.io/socket.io.js"></script> //console output is: Loading failed for the <script> with source “https://www.example.com/my_ip_number:8080/socket.io/socket.io.js”. //the most odd one <script src="https://my_ip_number/socket.io/socket.io.js"></script> //console […]

连接到websocket服务器:确定从JavaScript,不能从PHP

我正在使用socketio来运行一个websocket服务器。 var fs = require('fs'); var options = { key: fs.readFileSync('/etc/letsencrypt/live/my.domain.be/privkey.pem'), cert: fs.readFileSync('/etc/letsencrypt/live/my.domain.be/fullchain.pem') }; var app = require('https').createServer(options) , io = require('socket.io').listen(app) app.listen(6666); 连接到它从JavaScript(使用socket.io客户端)工作正常。 var socket = io.connect('wss://my.domain.be:6666'); 这也适用于: var socket = io.connect('https://my.domain.be:6666'); 现在我想连接使用PHP。 我在这里find了一个简单的PHP客户端: 如何使用WebSocket发送来自PHP的数据/文本进行处理? 但是在使用时我看不到传入的连接: $WebSocketClient = new WebsocketClient('wss://my.domain.be', 6666); $WebSocketClient->sendData("MyUserNameFromPHP"); 我得到的错误: 错误:22145040:无法find套接字传输“wss” – 您忘记configurationPHP时启用它? 使用时: $WebSocketClient = new WebsocketClient('https://my.domain.be', 6666); 我得到的错误: 错误:10905616:无法find套接字传输“https” […]

编写一个基于反应的聊天应用程序,实时更新Express,Mongodb,Nodejs

我正在编写一个聊天应用程序的应用程序,它需要使用websockets或socket.io来检查服务器中的更新。 它会将信息传递给所有的客户。 GitHub存储库已连接。 我想弄清楚如何实现websockets / socket.io。 如果任何人都可以给我一些关于文件放置的提示,或者帮我弄明白,那将是太棒了。 链接到该项目: https : //github.com/vschool-september-2017/chatter

SocketIO发射不会在高速路线内发射

下面的工作正常,我可以得到我的客户端应用程序的http响应,但socketio发射似乎并不工作。 我不知道为什么它不开火。 这是我的代码(删除了一些部分): app.js var express = require('express'); var port = process.env.PORT || 3000; var socketio = require('socket.io'); var app = express(); var server = require('http').Server(app); var io = socketio(server); var beacons = require('./routes/beacons')(io); app.use('/beacons', beacons); server.listen(port, () => { console.log('Listening on port '+port); }); io.on('connection', (socket) => { socket.on('beacon:show', function(data) { console.log('Show beacon: ' […]

来自服务器的SocketIO全局消息

我有node.js socket.io服务器。 我想每5秒钟向所有客户端发送消息。 这里我的过程到目前为止: var express = require('express'); var app = express(); var path = require('path'); var server = require('http').createServer(app); var io = require('../..')(server); var port = process.env.PORT || 3000; server.listen(port, function () { console.log('Server listening at port %d', port); }); app.use(express.static(path.join(__dirname, 'public'))); function PingPong(socket) { console.log('Send: Ping Pong, Number of Users: %d', numUsers); socket.emit('ping […]