[英]How to get websocket url path from php or node.js
My html code 我的html代码
var url='ws://localhost:8000/abc';
socket=new WebSocket(url);
socket.onopen=function(){
log('Success');
}
in php or node.js how to get url path abc ? 在php或node.js中如何获取url路径abc ?
If you're using the ws library for node you can get the URL from the second argument to ws.connection
which is the request object: 如果您将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.