ITADN

NetworkDiscoveryBase bug

#4071ClosedCrazy-Jammy 创建于 2025-12-03
C
Crazy-Jammycommented
```cs public void BroadcastDiscoveryRequest() { if (clientUdpClient == null) return; if (NetworkClient.isConnected) { StopDiscovery(); return; } IPEndPoint endPoint = new IPEndPoint(IPAddress.Broadcast, serverBroadcastListenPort); if (!string.IsNullOrWhiteSpace(BroadcastAddress)) { try { endPoint = new IPEndPoint(IPAddress.Parse(BroadcastAddress), serverBroadcastListenPort); } catch (Exception ex) { Debug.LogException(ex); } } using (NetworkWriterPooled writer = NetworkWriterPool.Get()) { writer.WriteLong(secretHandshake); try { Request request = GetRequest(); writer.Write(request); ArraySegment<byte> data = writer.ToArraySegment(); // The asynchronous operation here returns immediately, which may cause the write to be reclaimed and then erroneously modified by other references when sending data. clientUdpClient.SendAsync(data.Array, data.Count, endPoint); } catch (Exception) { // It is ok if we can't broadcast to one of the addresses } } } ```
关闭于 2025-12-23 2 条评论