Docker环境不支持Socket.IOControl

时间:2019-05-02 05:03:29

标签: c# docker sockets tcp

我正在使用Socket.IOControl方法保持TCP连接保持活动状态。此方法在我的win10 PC上可以正常使用,但在docker环境中不支持。

这里是Socket.IOControl

的用法
var keepAliveParameter = KeepAliveParameter( 5000, 5000 );
TcpClient.Client.IOControl( IOControlCode.KeepAliveValues, keepAliveParameter, null );

//...

private byte[] KeepAliveParameter( int time, int interval )
{
    int[] parameters = { 1, time, interval };
    byte[] byteArray = new byte[3 * sizeof( int )];
    System.Buffer.BlockCopy( parameters, 0, byteArray, 0, 3 * sizeof( int ) );
    return byteArray;
}

它引发以下异常:

  

System.PlatformNotSupportedException:Socket.IOControl处理Windows特定的控制代码,并且在此平台上不受支持。

dockerfile:

FROM microsoft/dotnet:2.2-sdk AS publish
COPY . /src
RUN dotnet restore /src/StressTestingServer/StressTestingServer.csproj --source http://192.168.10.149:5080/nuget --source https://api.nuget.org/v3/index.json
RUN dotnet publish /src/StressTestingServer/StressTestingServer.csproj --no-restore -c Release -o /app
RUN rm /app/appsettings.json

FROM microsoft/dotnet:2.2-runtime-alpine
WORKDIR /app
EXPOSE 8080
COPY --from=publish /app .
ENTRYPOINT dotnet StressTestingServer.dll

是否有任何解决方法或更好的解决方案来保持TCP连接正常?

0 个答案:

没有答案