You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows MessageWebSocket.ConnectAsync未每次刷新主机IP(DNS)问题排查

UWP MessageWebSocket 未重新解析Host文件修改后的主机IP问题

我有一个UWP应用,尝试与主机test.mydomain.com建立WebSocket连接(该主机实际不存在),使用的代码如下:

_websocket = new MessageWebSocket();
_websocket.Control.MessageType = SocketMessageType.Utf8;

_websocket.Closed += _websocket_Closed;
_websocket.MessageReceived += _websocket_MessageReceived;

Uri aoUri = new Uri(url);
                
_websocket.ConnectAsync(aoUri).Completed = (source, status) =>
{
   OnLog("_websocket.Information: " + _websocket.Information);

    if (status == AsyncStatus.Completed)
    {
        messageWriter = new DataWriter(_websocket.OutputStream);
        IsOpen = true;
        OnOpened();
    }
    else if (status == AsyncStatus.Error)
    {
        RaiseError(source.ErrorCode);
        EndConnection();
    }
};

测试过程

  1. 初始Host文件配置:
1.1.1.1 test.mydomain.com

此时通过Wireshark(过滤规则:ip.dst==1.1.1.1 and tcp.port==443)可看到多次尝试连接1.1.1.1:443,执行ipconfig /display dns显示配置正常。

  1. 修改Host文件为:
2.2.2.2 test.mydomain.com

执行ipconfig /display dns已显示修改后的配置,但Wireshark观测到:

  • 无法看到连接2.2.2.2:443的尝试(过滤规则:ip.dst==2.2.2.2 and tcp.port==443)
  • 组件仍持续尝试连接1.1.1.1:443

已知情况

  • 每次连接尝试都会销毁并重建MessageWebSocket对象
  • 重启应用后可正常连接Host文件配置的新IP
  • 连接前调用Dns.GetHostEntry(aoUri.Host)可获取正确的IP,与MessageWebSocket的行为不同

看起来MessageWebSocket每次尝试连接时并未重新解析主机名,请问有人知道原因吗?


内容的提问来源于stack exchange,提问作者jeremy salat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 00:00:57