gpt4 book ai didi

.net - ACI 未接收 UDP 通信

转载 作者:行者123 更新时间:2023-12-03 02:12:22 24 4
gpt4 key购买 nike

我希望在 Azure 容器实例中托管一个容器,监听 UDP 端口上的传入日志。我开发了 docker 镜像,可以在本地和我公司的内部网络中运行。想要在 Azure 中测试它,但我没有收到任何数据包...但是当我使用来自 github 的示例 UDP 监听器检查 UDP 连接时,它工作正常(我使用了那个: mendhak/docker-udp-listener )。

令我担心的是,我的目标容器实例收到了 0 个字节。看来端口已被关闭。

使用脚本部署 ACI:
az container create --resource-group <resource_group> --name sidecar --image <my_repository>/sidecar:latest --ip-address Public --ports 7777 --protocol UDP -e "UdpPort=7777"

此时我有点不知道发生了什么。

这是来自 Azure 的 NetworkBytesReceivedPerSecond 指标。在那段时间里,我发送了几个请求。

2022-07-15 08:14:00  Network Bytes Received Per Second  0.0
2022-07-15 08:15:00 Network Bytes Received Per Second 0.0
2022-07-15 08:16:00 Network Bytes Received Per Second 0.0
2022-07-15 08:17:00 Network Bytes Received Per Second 0.0
2022-07-15 08:18:00 Network Bytes Received Per Second 0.0
2022-07-15 08:19:00 Network Bytes Received Per Second 0.0
2022-07-15 08:20:00 Network Bytes Received Per Second 0.0
2022-07-15 08:21:00 Network Bytes Received Per Second 0.0
2022-07-15 08:22:00 Network Bytes Received Per Second 0.0
2022-07-15 08:23:00 Network Bytes Received Per Second 0.0
2022-07-15 08:24:00 Network Bytes Received Per Second 0.0
2022-07-15 08:25:00 Network Bytes Received Per Second 0.0
2022-07-15 08:26:00 Network Bytes Received Per Second 0.0
2022-07-15 08:27:00 Network Bytes Received Per Second 0.0
2022-07-15 08:28:00 Network Bytes Received Per Second 0.0
2022-07-15 08:29:00 Network Bytes Received Per Second 0.0
2022-07-15 08:30:00 Network Bytes Received Per Second 0.0
2022-07-15 08:31:00 Network Bytes Received Per Second 0.0
2022-07-15 08:32:00 Network Bytes Received Per Second 0.0
2022-07-15 08:33:00 Network Bytes Received Per Second 0.0
2022-07-15 08:34:00 Network Bytes Received Per Second 0.0
2022-07-15 08:35:00 Network Bytes Received Per Second 0.0
2022-07-15 08:36:00 Network Bytes Received Per Second 0.0
2022-07-15 08:37:00 Network Bytes Received Per Second 0.0
2022-07-15 08:38:00 Network Bytes Received Per Second
2022-07-15 08:39:00 Network Bytes Received Per Second 0.0
2022-07-15 08:40:00 Network Bytes Received Per Second 0.0
2022-07-15 08:41:00 Network Bytes Received Per Second
2022-07-15 08:42:00 Network Bytes Received Per Second 0.0
2022-07-15 08:43:00 Network Bytes Received Per Second 0.0
2022-07-15 08:44:00 Network Bytes Received Per Second 0.0
2022-07-15 08:45:00 Network Bytes Received Per Second 0.0

而且看起来 7777 端口确实在 UDP 中开放(从容器内部输出nestat -a):

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
udp6 0 0 0.0.0.0:7777 [::]:*
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 5013 /tmp/dotnet-diagnostic-19-1606-socket

我的套接字实现:

        public async Task Listen(CancellationToken cancelToken)
{
IPEndPoint localEndpoint = new IPEndPoint(IPAddress.Any, _port);

UdpSocket = new Socket(SocketType.Dgram, ProtocolType.Udp);
UdpSocket.Bind(localEndpoint);
await ReceiveAsync(cancelToken);
}

private async Task ReceiveAsync(CancellationToken cancelToken)
{
byte[] buffer = GC.AllocateArray<byte>(65527, pinned: true);
Memory<byte> bufferMemory = buffer.AsMemory();

while (!cancelToken.IsCancellationRequested)
{
try
{
SocketReceiveFromResult result = await UdpSocket.ReceiveFromAsync(bufferMemory, SocketFlags.None, _blankEndpoint);
if (result.ReceivedBytes > 0)
{
byte[] relevantBuffer = bufferMemory.Slice(0, result.ReceivedBytes).ToArray();
string message = Encoding.UTF8.GetString(relevantBuffer);
_onMessageReceived(result, message);
}
}
catch (SocketException)
{
break;
}
}
}

最佳答案

几天后,我再次检查通信,容器收到消息。一切似乎都运转良好。看起来是 Azure 不可用......我的配置是正确的。问题解决了。

关于.net - ACI 未接收 UDP 通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72990846/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com