简体   繁体   English

如何在特定端口上搜索响应式套接字服务器(如何在给定端口但没有其ip的情况下连接到服务器)?

[英]How to search for responsive socket servers on a particular port (How to connect to a server given the port but not having its ip)?

By having two (or more) computers (devices) connected via let's say a router, is it possible to connect to a socket server on a given port without knowing its IP address or at least get a list of all servers on that port (and communicate with each to see if that's the one I'm looking for)? 通过让两台(或更多台)计算机(设备)通过路由器连接,可以在不知道其IP地址的情况下连接到给定端口上的套接字服务器,或者至少获得该端口上所有服务器的列表(以及与每个人交流以查看是否是我要寻找的那个)?

I must add I'm a beginner in java socket programming (and socket programming in general) and have been using this only to initialize my client server: 我必须补充一点,我是Java套接字编程(和一般而言的套接字编程)的初学者,并且一直仅用于初始化客户端服务器:

    Socket socket = new Socket(serverIP, serverPort);

I've been able to have communication between client and server on two different computers connected by a wireless router, and I'm trying to implement that on two android devices. 我已经能够通过无线路由器在两台不同的计算机上进行客户端和服务器之间的通信,而我正在尝试在两个android设备上实现该功能。 The issue is IP address is not a thing to just ask from a user. 问题是IP地址不是仅向用户询问的问题。 That's why I wanna know how to connect to a server on a port I know without having its IP, or find all IPs that are active on that port (to perhaps try to communicate with each and see if one is the one I'm looking for) 这就是为什么我想知道如何在我知道的端口上连接服务器而又没有它的IP或找到该端口上所有活动的IP(也许尝试与每个IP通信并查看是否是我正在寻找的IP)的原因对于)

I don't know the exact solution for you how to implement it with Java sockets, but my first thought was to try broadcasting a specific message from the server and when the clients connected to the same network they can receive this message and they will know where it came from. 我不知道如何使用Java套接字实现它的确切解决方案,但是我首先想到的是尝试广播服务器中的特定消息,并且当客户端连接到同一网络时,他们可以接收到此消息,并且他们会知道它来自哪里。 ( or vice versa) ( 或相反亦然)

But, Multicasting is a better approach because: 但是,多播是一种更好的方法,因为:

"Broadcasting is inefficient as packets are sent to all nodes in the network, irrespective of whether they are interested in receiving the communication or not. This may be a waste of resources." “广播是无效的,因为数据包被发送到网络中的所有节点,而不管它们是否有兴趣接收通信。这可能会浪费资源。” see: https://www.baeldung.com/java-broadcast-multicast 参见: https : //www.baeldung.com/java-broadcast-multicast

Maybe this GitHub repo could be helpful for you: https://github.com/jbrucker/server-discovery 也许这个GitHub仓库可能对您有所帮助: https : //github.com/jbrucker/server-discovery

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

相关问题 Java:如何从一个端口上的客户端套接字连接到不同的服务器? - Java: how to connect to different servers from a client socket on one port? 如何在服务器套接字端检索客户端的IP和PORT? - How to retrieve client's IP and PORT on the server socket end? 如何在Apache Ignite中查找正在运行的服务器或客户端ip及其端口 - How to find running server or client ip and its port in Apache Ignite 如何使用 IP 地址和端口号连接到服务器套接字? (客户端运行在与服务器不同的机器上) - How do I connect to the server socket using the ip address and port number? (client is running on a different machine than server) 服务器如何获取客户端的IP和端口号TCP? - How do servers get client's IP and port number TCP? 如何获得Vaadin 7应用服务器的IP和端口? - How to get the Vaadin 7 application server IP and port? 如何识别NAT背后的服务器套接字端口 - How to identify Server Socket port behind NAT Java:检查给定的ip和端口是否是代理服务器 - Java: check if given ip and port is proxy server 如何从Android Tcp客户端套接字连接到具有公共IP的Java TCP服务器套接字? - How to connect to a Java TCP server socket having Public IP From Android Tcp Client Socket? 如何在平衡服务器上恢复端口 - How to recover the port on balanced servers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM