亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Azure WebSocket 不適用于 Go httpPlatformHandler

Azure WebSocket 不適用于 Go httpPlatformHandler

Go
慕哥9229398 2021-11-22 15:40:19
我很難讓 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

http://img1.sycdn.imooc.com//619b49820001165911180669.jpg

查看完整回答
反對 回復 2021-11-22
  • 1 回答
  • 0 關注
  • 167 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號