2016-03-03 33 views
1

我已经在OpenShift Cloud平台中通过Red-hat为NodeJs聊天应用程序部署了以下代码,在控制台(F12)和响应代码中没有出现任何错误,如OK 200。 。但应用程序无法正常Openshift Nodejs Socket.io问题,但是200 Ok响应

服务器(你可以找到在https://github.com/varund29/openshift/blob/master/index.js完整的源代码)

var express = require('express'); 
var app = express(); 
var server = require('http').createServer(app); 
var io = require('socket.io').listen(server, { origins:'http://nodejs-atnodejs.rhcloud.com:8000' }); 
app.get('/', function (req, res) { 
    res.sendfile('index.html'); 
}); 
io.on('connection', function (socket) { 
    socket.on('chatmessage', function (msg) { 
     console.log('index.js(socket.on)==' + msg); 
     io.emit('chatmessage', msg); 
    }); 
}); 

server.listen(process.env.OPENSHIFT_NODEJS_PORT, process.env.OPENSHIFT_NODEJS_IP); 

客户端(你可以找到在https://github.com/varund29/openshift/blob/master/index.html完整的源代码)

src="http://nodejs-atnodejs.rhcloud.com:8000/socket.io/socket.io.js 
src="http://code.jquery.com/jquery-1.11.1.js" 

    var socket = io.connect('http://nodejs-atnodejs.rhcloud.com:8000'); 
     $('button').click(function (e) { 
      console.log('index.html($(button).click)=' + $('#m').val()); 
      socket.emit('chatmessage', $('#m').val()); 
      $('#m').val(''); 
      return false; 
     }); 
     socket.on('chatmessage', function (msg) { 
      console.log('index.html(socket.on)==' + msg); 
      $('#messages').append($('<li>').text(msg)); 
     }); 

HTML正文是

<ul id="messages"></ul> 
    <form action=""> 
     <input id="m" autocomplete="off" /> 
     <button>Send</button> 
    </form> 
+0

我参考了对于上述从http://socket.io/get-started/chat/ –

回答

3

当我跑到你的代码我在我的日志文件中的以下的错误在我的OpenShift在线齿轮:

Option log level is not valid. Please refer to the README. 
Option polling duration is not valid. Please refer to the README. 

所以我在你index.js文件中注释掉以下行:

io.set('log level', 1);     // reduce logging 
io.set('transports', ['xhr-polling']); 
io.set("polling duration", 10); 

而现在它似乎工作正常。你可以在这里进行测试:http://nodejs-cdaley.rhcloud.com/ 可以看到这里的代码:https://github.com/developercorey/nodejs

+0

请告诉我如何才能找到日志文件在OpenShift中。 –

+0

谢谢,现在它的工作正常。我发现问题是如果“依赖关系”:{“socket.io”:“〜9.6.0”}它不工作。使用“依赖项”很好地工作:{“socket.io”:“1.2.0”} - –

+0

您可以按照以下说明找到您的日志文件:https://developers.openshift.com/en/managing-log-files html的 – 2016-03-03 14:55:40

相关问题