Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net DotNet似乎允许两个进程打开同一端口?_.net_Linux_Sockets_Docker_.net Core - Fatal编程技术网

.net DotNet似乎允许两个进程打开同一端口?

.net DotNet似乎允许两个进程打开同一端口?,.net,linux,sockets,docker,.net-core,.net,Linux,Sockets,Docker,.net Core,我在Dockercentos:7容器上运行DotNet服务,我遇到了代码问题,在DotNet发布和DotNet运行的情况下,我运行的代码不同 我目前运行的dotnet服务监听端口3480。我运行的dotnet代码似乎也试图在同一端口上实例化TcpListener 在dotnet运行模式下,似乎发生了这种情况,在发布中,我得到了一个使用中的地址错误 所以在我运行代码之前,我有一个net stat-lntp Active Internet connections (only servers) Pro

我在Docker
centos:7
容器上运行DotNet服务,我遇到了代码问题,在
DotNet发布
DotNet运行
的情况下,我运行的代码不同

我目前运行的dotnet服务监听端口
3480
。我运行的dotnet代码似乎也试图在同一端口上实例化
TcpListener

dotnet运行
模式下,似乎发生了这种情况,在发布中,我得到了一个使用中的
地址
错误

所以在我运行代码之前,我有一个
net stat-lntp

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:3840            0.0.0.0:*               LISTEN      5017/dotnet
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      -
其中pid 5017我的服务正在TCP端口上侦听

启动代码后,情况如下所示:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        1      0 0.0.0.0:3840            0.0.0.0:*               LISTEN      5247/dotnet
tcp        0      0 172.17.0.2:4000         0.0.0.0:*               LISTEN      5247/dotnet
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      -
PID 5247似乎已经接管了

然后,当我终止代码时,我们返回到该状态:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:3840            0.0.0.0:*               LISTEN      5017/dotnet
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      -
我能想到的唯一区别是,当我执行
ps-eopid命令时,我得到以下结果:

 5017 /usr/bin/dotnet /usr/share/my-agent/My.Agent.Linux.dll
 5247 dotnet exec /devel/SandBox/bin/Debug/netcoreapp2.0/ServerSandbox.dll
 5017 /usr/bin/dotnet /usr/share/my-agent/My.Agent.Linux.dll
 8405 ./publish/My.ServerSandbox
如果我运行发布的版本
dotnet publish-o publish-r linux-x64-c Debug
,我会得到以下结果:

 5017 /usr/bin/dotnet /usr/share/my-agent/My.Agent.Linux.dll
 5247 dotnet exec /devel/SandBox/bin/Debug/netcoreapp2.0/ServerSandbox.dll
 5017 /usr/bin/dotnet /usr/share/my-agent/My.Agent.Linux.dll
 8405 ./publish/My.ServerSandbox
当代码崩溃时,
PID
控制端口
4080
保持不变

我的想法是,
DotNet运行时
以某种方式实际管理端口本身,这就是为什么它允许同一端口打开两次,就像我发布代码时一样,我使用的是嵌入式运行时,因此我们被发现做了一些不应该发生的事情

以前有人见过这种行为吗?我一直在绕圈子,为什么我不能让发布的版本工作,在深入挖掘之后,我认为运行版本不应该工作


感谢您提供的任何建议/帮助

在做了一些研究之后,我们的服务器似乎确实在做我们怀疑的事情。我们将源代码更改为两次不打开同一个端口,一切都协调一致。至于为什么这是可能的,我仍然感到困惑——因此,如果你遇到类似的情况,希望这个问题能给你一些安慰。

.NET不能做操作系统不允许的事情。在一种情况下,尽管您似乎正在运行调试代码-
/devel/SandBox/bin/debug/netcoreapp2.0/ServerSandbox.dll
<代码>发布
在打包之前生成发布版本。