简体   繁体   English

如果客户端的端口在服务器发现期间已被占用,如何更改服务器中的UDP广播端口?

[英]How to change UDP broadcast port in the server if client's port is already occupied during server discovery?

I am trying to implement a server discovery between a PC (server) and an android phone, broadcasting a message from the server on a common port (8888). 我正在尝试在PC(服务器)和Android手机之间实现服务器发现,在公共端口(8888)上从服务器广播消息。 I wonder what should I do if the port is already taken in the client, how can I change port on both, so that the client receives the broadcast message? 我想知道如果端口已经在客户端中,我应该怎么做,如何更改端口,以便客户端接收广播消息? Should I use any specific network discovery protocol (UPnP or similar)? 我应该使用任何特定的网络发现协议(UPnP或类似的)吗?

Sorry if it is a basic question but I am not familiar with network programming. 对不起,如果这是一个基本问题,但我不熟悉网络编程。 I will edit my question according to your observations. 我会根据你的观察编辑我的问题。

I could only find this, but it has no answer: How to listen for a UDP broadcast when the default port could be already taken 我只能找到这个,但它没有答案: 如何在已经采用默认端口时监听UDP广播

Ideally, use an existing service discovery protocol like SSDP. 理想情况下,使用现有的服务发现协议,如SSDP。 There is some prior work on this for Android you may be able to build from: https://github.com/resourcepool/ssdp-client 有一些关于Android的先前工作,您可以从以下构建: https//github.com/resourcepool/ssdp-client

The reasons to use SSDP: 使用SSDP的原因:

  • You're not going to run into any conflicts since the ports are properly reserved. 由于端口已正确保留,因此您不会遇到任何冲突。
  • It uses multicast rather than broadcast. 它使用多播而不是广播。 This may not matter much for you on your network, but IPv6 doesn't support broadcast, so it's already compatible. 这可能对您的网络没什么影响,但IPv6不支持广播,因此它已经兼容。
  • It's a standard protocol, so network administrators know what it is and can handle the traffic. 它是一种标准协议,因此网络管理员知道它是什么并且可以处理流量。

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

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