2015-11-12 15:40
浏览 51

Azure WebSocket无法与Go httpPlatformHandler一起使用

I'm having a hard time making websocket works on an Azure Web App, I'm currently porting a Node app from Azure to a Go app.

WebSocket is enable on the portal and here's my web.config

<?xml version="1.0" encoding="UTF-8"?>
        <customErrors mode="Off"/>
        <webSocket enabled="false" />
            <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
        <httpPlatform stdoutLogEnabled="true" processPath="d:\home\site\wwwroot\v-0.0.10.exe"
              <environmentVariable name="GOROOT" value="d:\home\site\wwwroot\go" />

Of course locally it's working fine. At first I only tried this sample:

package main

import (

func echoHandler(ws *websocket.Conn) {
    io.Copy(ws, ws)

func main() {
    http.Handle("/echo", websocket.Handler(echoHandler))
    http.Handle("/", http.FileServer(http.Dir(".")))
    err := http.ListenAndServe(":"+os.Getevn("HTTP_PLATFORM_PORT"), nil)
    if err != nil {
        panic("ListenAndServe: " + err.Error())

On the client side I simply try to connect:

var ws = new WebSocket("url")
ws.onopen = function() { ws.send("test"); }
ws.onmessage = function(e) { console.log(; }

When deployed on Azure, the readystate always stays at 0, onopen is never call. It ultimately failed saying there's an error connecting:

WebSocket connection to 'wss://***' failed: Error during WebSocket handshake: Unexpected response code: 500

I even tried with Gorilla Websocket example to see if the Go extended package was in cause.

Things I tried:

  1. Removed the <webSocket enabled="false" /> from web.config [same issue but it appears to take longer before occuring

  2. Adding a standard http.HandleFunc to serve a "standard" page and it works fine.

I have a handful of Go app deploy to Azure, it's just the first one that I would need to use websocket, and I would like to know what I'm doing wrong / not understanding.

Any help would be greatly appreciated

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanhuoyao7011 2015-11-13 02:17

    I reference your code and created a sample, it is working for me. I didn`t do any custom web.config but using the default one come from Azure Deployment script.

    here is the sample repo:

    enter image description here

    点赞 打赏 评论

相关推荐 更多相似问题