Azure Mobile Service and socket.io

I am trying to create an HTML5 / JS application and use the Azure mobile service for my backend.

Based on a post from ScottGu , where it demonstrates source support and support for the npm module, I wonder if it is possible to use socket.io to enable real-time notifications and use WebSockets.

I can see how you can connect the module and use it for each specific request (for example, when the client sends POSTS to the resource, add a hook to broadcast the creation of the resource to all clients), but I do not know how to configure and share the socket object .io.

NB. I know about the built-in support for push notifications for iOS, Windows and Google, but it still does not provide a ready-made solution for web projects, so you need to use socket.io (or any other SignalR-esque equivalent).

+6
source share
2 answers

WebSocket should be fine on Azure Mobile Services because it simply โ€œdowngradesโ€ the HTTP connection back to the framing Socket (more like reliable UDP). But there are a few caveats:

  • If you use Socket.IO, browsers / proxies do not support WebSocket by default for XHR. But Socket.IO through XHR requires many URL endpoints and will not work in Azure Mobile Services. Socket.IO protocol specification details at https://github.com/learnboost/socket.io-spec
  • You need to use Redis (redis.io) to support the server farm through Socket.IO, which requires a Linux box. At the moment, they have an experimental build on the Windows platform.

I would rather install a different set of computers designed for the Socket.IO server so that it does not fail in browsers / proxies that do not support WebSocket. Then, when someone goes to the API on Azure Mobile Services, the API will queue the message in the message queue and signal all your Socket.IO servers to broadcast the message.

+1
source

Socket.IO support was added by running script extension

var path = require('path'); exports.startup = function (context, done) { var io = require('socket.io')(context.app.server); io.on('connection', function(socket){ socket.on('chat message', function(msg){ io.emit('chat message', msg); }); }); context.app.get('/public/chat.html', function(req, res) { res.sendfile(path.resolve(__dirname, '../public/chat.html')); }); done(); } 

For more details see: http://azure.microsoft.com/blog/2014/08/26/how-to-use-socket-io-with-azure-mobile-service-node-backend/

+1
source

Source: https://habr.com/ru/post/955854/


All Articles