[英]socket.io how to get server socket listen address and port
這是我在服務器端的簡化代碼示例,我需要獲取服務器套接字正在偵聽的 ip(最好是主機名)和端口,給定回調中的 socket 參數並假設我在這里沒有可訪問的 io 變量
function myCallback(socket, data){
//how do i get, to which ip or hostname and port the socket argument is listening
}
io.on('connection', function(socket){
socket.on('event',function(data){
myCallback(socket,data);
});
});
您可以使用:
function myCallback(socket, data) {
var address = socket.handshake.address;
console.log('New connection from ' + address.address + ':' + address.port);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.