我很難讓 websocket 在 Azure Web 應用程序上運行,我目前正在將 Node 應用程序從 Azure 移植到 Go 應用程序。WebSocket 在門戶上啟用,這是我的 web.config<?xml version="1.0" encoding="UTF-8"?><configuration> <system.web> <customErrors mode="Off"/> </system.web> <system.webServer> <webSocket enabled="false" /> <handlers> <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" /> </handlers> <httpPlatform stdoutLogEnabled="true" processPath="d:\home\site\wwwroot\v-0.0.10.exe" arguments="" startupTimeLimit="60"> <environmentVariables> <environmentVariable name="GOROOT" value="d:\home\site\wwwroot\go" /> </environmentVariables> </httpPlatform> </system.webServer></configuration>當然在本地它工作正常。起初我只試過這個樣本:package mainimport ( "code.google.com/p/go.net/websocket" "io" "net/http" "os")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()) }}在客戶端,我只是嘗試連接:var ws = new WebSocket("url")ws.onopen = function() { ws.send("test"); }ws.onmessage = function(e) { console.log(e.data); }在 Azure 上部署時,就緒狀態始終保持為 0,永遠不會調用 onopen。它最終失敗,說連接出錯:WebSocket connection to 'wss://***.azurewebsites.net/echo' failed: Error during WebSocket handshake: Unexpected response code: 500我什至嘗試使用 Gorilla Websocket 示例來查看 Go 擴展包是否有問題。我嘗試過的事情:<webSocket enabled="false" />從 web.config 中刪除了[同樣的問題,但在發生之前似乎需要更長的時間添加一個標準http.HandleFunc來提供“標準”頁面,它工作正常。我有一些 Go 應用程序部署到 Azure,這只是我需要使用 websocket 的第一個應用程序,我想知道我做錯了什么/不理解。任何幫助將不勝感激
1 回答

幕布斯6054654
TA貢獻1876條經驗 獲得超7個贊
我參考了您的代碼并創建了一個示例,它對我有用。我沒有做任何自定義的 web.config,而是使用來自 Azure 部署腳本的默認配置。
這是示例存儲庫:https : //github.com/shrimpy/gowebsockettry
- 1 回答
- 0 關注
- 167 瀏覽
添加回答
舉報
0/150
提交
取消