简体   繁体   English

对于javascript中的websocket连接,如果想与其他设备通信,我如何获得可以通过websocket连接传递的IP地址?

[英]For websocket connection in javascript if wants to communicate to other device how I can get IP address which I can pass through websocket connection?

var ip = ""; 
var ws = new WebSocket("ws://"+ip+":9998");

It is not possible to find private IP address.无法找到私有 IP 地址。 or I need any server side language like node.js?或者我需要像 node.js 这样的服务器端语言?

You would need to know the IP address in order to do that.您需要知道 IP 地址才能执行此操作。 There is no way of figuring out the IP address of other clients.无法确定其他客户端的 IP 地址。 If you wanted to connect to another socket without knowing the IP address you would use a server to connect the endpoints and route the messages.如果您想在不知道 IP 地址的情况下连接到另一个套接字,您将使用服务器连接端点并路由消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM