簡體   English   中英

如何從php或node.js獲取websocket URL路徑

[英]How to get websocket url path from php or node.js

我的html代碼

var url='ws://localhost:8000/abc';
  socket=new WebSocket(url);
  socket.onopen=function(){
    log('Success');
  }

在php或node.js中如何獲取url路徑abc

沒有原生方法可以在PHP或Node中使用websocket。 您需要使用某種類型的庫。 幸運的是,有很多可供選擇:

節點JS

PHP

如果您將ws庫用於節點 ,則可以從第二個參數獲取ws.connection的URL,該參數是請求對象:

const server = new http.createServer()
const wss = new WebSocket.Server({ server })

wss.on('connection', (ws, req) => {
  console.log(req.url)
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM