Using WebSockets with Windows Azure Web Sites

Using WebSockets with Windows Azure Web Sites

Rate This
  • Comments 2

If you missed the announcement the other day, WebSockets are now supported in Windows Azure Web Sites. This means you can now use things like Socket.io from web sites instead of having to use a Cloud Service worker role.

To get this working

  1. Create a an application that uses WebSockets using a language that works with Web Sites. For example, I'm using the Socket.io example chat app.

    Since the chat example has some hardcoded paths for socket.io, as well as the port, the following changes have to be made for it to work with Web Sites:

    1. Edit app.js and change the following:

      original line

      , sio = require('..//..//lib//socket.io'); 

      updated line

      , sio = require('socket.io') 

      original line

      app.listen(3000, function () { 

      updated line

      app.listen(process.env.PORT, function () { 
    2. Use npm to add socket.io as a dependency in the package.json file:

      npm install socket.io --save

  2. Create a new web site and deploy the application to it. I used the cross-platform command-line interface: to create a new web site. Here's the commands I used:

    azure site create mywebsocketapp --location "East US" --git 

    That gives it a name, a location, and sets up git in the folder you run this command from (the folder that your application files are in.) The --git parameter also creates a remote named 'azure' that can be used to push the files up.

    1. Add and commit the files:
      git add .
      git commit -m "initial commit"
    2. Push to azure:
      git push azure master

      As this command processes, it should install all the required modules on the server. This can take a while the first time through.

  3. Go to the Windows Azure Management Console, select web sites, select your web site, and go to the CONFIGURE page. Here, scroll down and enable Web Sockets, then click the Save icon.

    Once you turn the switch to on and save the changes, WebSocket support should start working for the application.

Summary

That's it. That little switch in the UI is all there is to enabling it. Hopefully support for enabling it will be coming to the command-line tools, but for now it looks like you have to enable it in the portal.

Leave a Comment
  • Please add 4 and 2 and type the answer here:
  • Post
  • Supposing  I wanna create a game, how many clients can i Get connected if Im using Azure website?

    Somewhere I read i can have:

    Free:  (5) concurrent connections per website instance

    Shared: (35) concurrent connections per website instance

    Standard: (350) concurrent connections per website instance

    Is it true....It seems a very low number... :\

  • It took some digging around, but I was able to confirm that these limits do exist, and yeah; kinda low. They are mentioned in passing at blogs.msdn.com/.../introduction-to-websockets-on-windows-azure-web-sites.aspx.

    I talked to one of the program managers for Windows Azure Web Sites, so engineering is aware of the limitation and that people want it to go away (or at least give more connections.)

    Unfortunately, it looks like you will have to use something like a Cloud Service or VM to get a higher number of connections on Windows Azure.

Page 1 of 1 (2 items)