Tag: websocket

Nodejs:基于URL的websocket路由,无需端口代理

我正在尝试在html5中使用node.js中的服务器端逻辑进行游戏,并使用原始websockets(而不是Socket.IO,我需要二进制数据)。 我希望有多个“房间”,因此多个websocket服务器,都有单独的URL。 目前,我只find了一种方法,让每个websocket服务器连接到一个特定的端口,然后代理升级请求(不完全知道它是如何工作的)基于URL的正确的端口。 它在我的电脑上运行。 问题是,当我尝试将其提交给PaaS提供程序(AppFog)时,代码失败,因为它们不允许打开提供的http端口以外的任何端口。 这是一个相当清晰的我的代码版本: //start web server (basic static express server) on 8080 // … //start game server and listen to port 9000 // I use the ws module for websockets // I plan to have a couple of these "game servers" // … //open the proxy server. var httpProxy= require('http-proxy'); var webProxyServer […]

Socket.io和Webscocket在同一台服务器上侦听

我需要在socket.io和websocket(来自'ws'包)处理程序之间共享相同的http服务器。 不幸的是,尽pipe他们正在监听不同的前缀,第一个是监听/socket.io,第二个监听到/ websocket,因为某些原因,如果他们运行在同一台服务器上,websocket工作不正常。 我做了一些debugging,但似乎这两个库正确处理请求,但最终只有socket.io正常工作。 任何想法如何解决?

OpenShift WebSocket下降到xhr轮询没有websocket

我很肯定它在一个星期前工作。 但是几天之后,xhr-polling就是我所得到的一切。 它在我的本地机器上使用websockects连接工作正常,但在Openshift中没有。 如果我问我的Openshift服务器有关运输,它只会给我回:[“htmlfile”,“xhr轮询”,“jsonp轮询”],如果我强迫它使用websockets失败。 这是我在客户端上使用的url格式:var socket = io.connect('ws://mysite-myuser.rhcloud.com:8000'); 并在浏览器上加载网站: http : //mysite-myuser.rhcloud.com 我的服务器是节点与socket.io,并使用websocket作为运输本地工作正常。 有什么改变吗? 或者我可以改变一些东西,以获得sockets作为运输?

websocket php vs node js

有人可以说“websocket PHP” http://www.php.net/manual/en/sockets.examples.php >和node.js之间有什么区别吗? 。 我有使用websocket php聊天,但我不知道会更好,如果这个聊天将移动到node.js?

我将如何build立一个没有图书馆的NodeJS Websocket服务器

我最近在NodeJS中构build了一个小型的JSON webservice,并且有兴趣将它扩展为通过WebSockets接受请求。 到目前为止,我发现的大部分WebSocket教程都是基于像SocketIO这样的第三方模块。 编写WebSocket服务器需要什么? 假设跨浏览器兼容性在这里不是问题,并且我所有的客户都可以访问一个体面的浏览器。

Sails.js到客户端使用sails.sockets.join和sails.sockets.broadcast不返回到客户端的信息

我试图在客户端使用Sails.js和sails.io.js创build一对一聊天。 我可以得到io.socket.get和io.socket.post的工作,但我没有能够从sails.sockets.broadcast或Model.publish接收任何东西, sails.sockets.broadcast Model.publish : 使用Sails.js进行个性化聊天 或在这里 Sails.js + socket.io:从服务器发送消息到客户端 服务器端代码: UserController.js module.exports = { listen: function(req, res) { console.log("about to join " + userId); sails.sockets.join(req.socket, req.param('userId')); } }; 来自: http : //beta.sailsjs.org/#/documentation/reference/sails.sockets/sails.sockets.join.html MessageController.js // Some code to get userId and message model here console.log("about to broadcast on " + userId); sails.sockets.broadcast(userId, 'conversation_message', message); // […]

Socket.IO不使用回退方法

我有一个节点服务器运行一个socket.io服务器和一个客户端来使用它。 简单的故事,我需要能够在两者之间传递信息。 这是在支持Web套接字的浏览器中按预期工作,但是当需要使用后备方法时,它不起作用。 我应该提到,页面是从apache服务器提供的,节点服务器仅用于特定的页面。 我正在使用的代码如下,我已经修理了一段时间,不知道如何解决这个问题。 另外值得一提的是,当页面在IE9中打开(websockets不支持),logging connection.io.engine.transport.name会给“websocket”。 客户: connection = io(window.location.protocol + '//localhost:8888', { 'reconnect': false, 'max reconnection attempts': 0, 'transports': [ 'websocket', 'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling' ] }); connection.on('connect',function () { console.log("Socket is open"); $('#dc-status').hide(); connection.emit('message',JSON.stringify(info)); connection.on('message',function (e) { //DO SOMETHING WITH THE DATA RECIEVED }); }); 服务器:var ioserver = require('socket.io'); var io = […]

通过websocket客户端/服务器连接问题webrtc

不知道是否有人有什么我在做什么错误在这里: 我一直在: http : //blog.felixhagspiel.de/index.php/posts/create-your-own-videochat-application-with-html-and-javascript 该指南工作得很好,我已经通过nodejs进行了testing,所有工作都非常好。 我现在试图把这个例子转换成groovy。 在一个Grails插件中,并遇到一些问题。 所以这就是我所在的地方:打扰一下我的头撞砖墙的实际代码的状态:) 所有者/服务器创build空间 – 很好 客户来了,发送报价(收到的报价,但客户端断开WebSocket) 服务器/所有者收到报价,但试图发送回答 – 因为客户端断开连接没有发送回…. https://github.com/vahidhedayati/playground/blob/master/grails-wschat-plugin/src/groovy/grails/plugin/wschat/WsCamEndpoint.groovy#L72 这是websocket发送到parsing操作的扩展类的地方: https://github.com/vahidhedayati/playground/blob/master/grails-wschat-plugin/src/groovy/grails/plugin/wschat/ChatUtils.groovy#L244 呼叫: https://github.com/vahidhedayati/playground/blob/master/grails-wschat-plugin/src/groovy/grails/plugin/wschat/ChatUtils.groovy#L570 https://github.com/vahidhedayati/playground/blob/master/grails-wschat-plugin/src/groovy/grails/plugin/wschat/ChatUtils.groovy#L598 https://github.com/vahidhedayati/playground/blob/master/grails-wschat-plugin/src/groovy/grails/plugin/wschat/ChatUtils.groovy#L575 private void jsonmessageUser(Session userSession,String msg) { userSession.getBasicRemote().sendText(msg as String) } private void jsonmessageOther(Session userSession,String msg) { Iterator<Session> iterator=camsessions?.iterator() if (iterator) { while (iterator?.hasNext()) { def crec=iterator?.next() if (crec.isOpen()) { def cuser=crec.getUserProperties().get("camuser").toString() def […]

使用Socket.io将套接字传递给Node.js中的模块

我有一个模块 var exports = module.exports = {}; exports.refresh = function (msg) { socket.emit('refresh', { message: msg }); } exports.lock = function (msg) { socket.emit('lock', { message: msg }); } 并在我的server.js我定义 var io = require("socket.io").listen(server); 并调用模块 var period = require('./server/functions/period.js'); 我怎样才能将Socket传递给模块(period.js),以便我可以访问套接字方法,例如socket.emit , broadcast和io.sockets.emit 。

400,502,503错误与Websockets

我正在使用Socket.io,Node.js和Openshift进行多人游戏。 它工作了一段时间,但我做了一些小的改变,现在与我改变的东西无关。 当第二个玩家试图join游戏时,它会将所有人都引导出来,对于任何其他进入该网站的人显示503错误。 对于第二个玩家,我得到了很多控制台错误,包括 WebSocket connection to 'ws://avalon-evao.rhcloud.com/socket.io/?EIO=3&transport=websocket&sid=d5smykffy4EWHxgIAAAC' failed: Error during WebSocket handshake: Unexpected response code: 400 http://avalon-evao.rhcloud.com/socket.io/?EIO=3&transport=polling&t=1421020862973-4&sid=d5smykffy4EWHxgIAAAC Failed to load resource: the server responded with a status of 502 (Bad Gateway) http://avalon-evao.rhcloud.com/socket.io/?EIO=3&transport=polling&t=1421020865831-6&sid=d5smykffy4EWHxgIAAAC Failed to load resource: the server responded with a status of 503 (Service Unavailable) socket.io-1.2.0.js:2 WebSocket connection to 'ws://avalon-evao.rhcloud.com/socket.io/?EIO=3&transport=websocket&sid=c-fwcJaMkp_9rl5CAAAA' failed: WebSocket is […]