安裝 Gateway過程1、下載gateway zip包linux版,http://www.workerman.net/download2、使用Mac自帶的php無效,報Please install pcntl extension. See http://doc3.workerman.net/appendices/install-extension.html ...
1、下載gateway zip包linux版,http://www.workerman.net/download
2、使用Mac自帶的php無效,報Please install pcntl extension. See http://doc3.workerman.net/appendices/install-extension.html
,沒有去深究怎么安裝擴展,而是改用了xmapp的可以
3、嘗試使用小程序連接,小程序沒有執(zhí)行沒有報錯
原因是:協(xié)議寫錯,正確寫法是ws://,我錯寫成wss://
4、Error during WebSocket handshake: Invalid status line
原因是web socket 協(xié)議不一樣,導(dǎo)致不通,workerman demo自帶的的text協(xié)議,用于telnet調(diào)試
通過改動start_gateway.php第21行
$gateway = new Gateway("websocket://0.0.0.0:8282");
于是就成功了
5、通過onSocketMessage接收服務(wù)端發(fā)來的消息
onLoad: function () {
wx.connectSocket({
url: 'ws://127.0.0.1:8282',
success: function (res) { console.log('連接成功')
},
fail: function (res) { console.log('連接失敗')
}
})
wx.onSocketOpen(function(res) { console.log('WebSocket連接已打開!')
wx.sendSocketMessage({
data: "huangxj"
})
})
wx.onSocketError(function(res){ console.log('WebSocket連接打開失敗,請檢查!')
})
wx.onSocketMessage(function(res) { console.log('收到服務(wù)器內(nèi)容:' + res.data)
})
}
順便記錄2條關(guān)于php的命令
php --ini
查看php.ini所在目錄
php -m
查看已安裝哪些擴展
小程序源碼地址:http://git.oschina.net/dotton/demo-wx,即時通信文件夾下