Joined January 2013
·
Posted to
Socket.io and OpenShift Websockets
over 1 year
ago
@camillo777 yes. So, for plain WebSockets ws:// you will use port 8000 and for secured connections wss:// port 8443. Here’s an example:
http://app-lovingwebsockets.rhcloud.com/ <= your current HTTP URL
http://app-lovingwebsockets.rhcloud.com:8000/ <= WebSockets enables HTTP URL
https://app-lovingwebsockets.rhcloud.com/ <= your current HTTPs URL
https://app-lovingwebsockets.rhcloud.com:8443/ <= WebSockets enables HTTPs URL
You can find more details here: https://www.openshift.com/blogs/paas-websockets
Posted to
Socket.io and OpenShift Websockets
over 1 year
ago
On the server side you should use the default port provided by openshift:
self.port = process.env.OPENSHIFT_INTERNAL_PORT || process.env.OPENSHIFT_NODEJS_PORT || 8080;
In this way I initialized the socket.io on the server side:
// socket.io initialization on the server side
self.initializeSocketIO = function() {
self.server = require('http').createServer(self.app);
self.io = require('socket.io').listen(self.server);
self.io.enable('browser client minification'); // send minified client
self.io.enable('browser client etag'); // apply etag caching logic based on version number
self.io.enable('browser client gzip'); // gzip the file
self.io.set('log level', 1); // reduce logging
self.io.set('transports', [
'websocket'
]);
return this;
}
self.addSocketIOEvents = function() {
self.io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
}
/**
* Initializes the sample application.
*/
self.initialize = function() {
self.setupVariables();
self.populateCache();
self.setupTerminationHandlers();
// Create the express server and routes.
self.initializeServer();
self.initializeSocketIO().addSocketIOEvents();
};
On the client side I used it in this way (index.html):
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
</head>
<body>
ok
</body>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('ws://you-app.rhcloud.com:8000/');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
</html>
It should work fine for you. You used a bad port number.
Achievements
227 Karma
15,280 Total ProTip Views
![](https://coderwall.com/assets/badges/walrus-1f517cbbd8f030099b8386c53d4ee40fece3fa146b6362accb3abddb436482cb.png)
Walrus
The walrus is no stranger to variety. Use at least 4 different languages throughout all your repos
![](https://coderwall.com/assets/badges/mongoose-299fb33af2a4e416505b484d73e79ee3ff1840f3c7385d6bbbc158f76be054cb.png)
Mongoose
Have at least one original repo where Ruby is the dominant language
![](https://coderwall.com/assets/badges/beaver-4aaa0657e89d77a213defc49d173e7bca9b1e93222cdb2c9ae814380fdd4ea38.png)
Beaver
Have at least one original repo where go is the dominant language
![](https://coderwall.com/assets/badges/charity-bab6d575c53894cc9e395db7cdb1f0f91f176fa0cc8122c5f824e672f3d556a4.png)
Charity
Fork and commit to someone's open source project in need
@camillo777 yes, you should use ws://app-lovingwebsockets.rhcloud.com:8000/