Skip to content

2.0.2版本中,在.net core webapi 程序中启动多个服务器实例时,同时使用websocket 服务与udp 服务 出现启动失败, #813

@w419894293

Description

@w419894293

info: SuperSocketService[0]
The listener [Ip=Any, Port=9995, AuthenticationOptions=, Path=, BackLog=0, NoDelay=False] has been started.
info: SuperSocketService[0]
The listener [Ip=Any, Port=9996, AuthenticationOptions=, Path=, BackLog=0, NoDelay=False] has been started.
fail: UdpConnectionFactory[0]
The listener[Ip=Any, Port=9995, AuthenticationOptions=, Path=, BackLog=0, NoDelay=False] failed to start.
System.Net.Sockets.SocketException (10048): 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。
at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, Boolean disconnectOnFailure, String callerName)
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at SuperSocket.Udp.UdpConnectionListener.Start()
fail: SuperSocketService[0]
Failed to listen Ip=Any, Port=9995, AuthenticationOptions=, Path=, BackLog=0, NoDelay=False.
fail: UdpConnectionFactory[0]
The listener[Ip=Any, Port=9996, AuthenticationOptions=, Path=, BackLog=0, NoDelay=False] failed to start.
System.Net.Sockets.SocketException (10048): 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。
at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, Boolean disconnectOnFailure, String callerName)
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at SuperSocket.Udp.UdpConnectionListener.Start()
fail: SuperSocketService[0]
Failed to listen Ip=Any, Port=9996, AuthenticationOptions=, Path=, BackLog=0, NoDelay=False.
fail: SuperSocketService[0]
Failed to start any listener.
fail: Microsoft.Extensions.Hosting.Internal.Host[11]
Hosting failed to start
System.Exception: Failed to start the server.
at SuperSocket.Server.SuperSocketService1.Microsoft.Extensions.Hosting.IHostedService.StartAsync(CancellationToken cancellationToken) at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token) at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List1 exceptions, Func3 operation)
info: SuperSocketService[0]
The listener [Ip=Any, Port=9996, AuthenticationOptions=, Path=, BackLog=0, NoDelay=False] has been stopped.
info: SuperSocketService[0]
The listener [Ip=Any, Port=9995, AuthenticationOptions=, Path=, BackLog=0, NoDelay=False] has been stopped.

以下为注册两个服务实际代码:

builder.Host.AsSuperSocketHostBuilder<RawDataPackage>()
    .UseHostedService<UDPServer>()
    .UseSession<UDPServerSession>()
    .ConfigureServerOptions((ctx, config) => { return config.GetSection("UDPServer"); })
    .UsePipelineFilter<RawFilter>()
    .UsePackageHandler(ServerMethods.UdpDataPackageHandl)
    .UseUdp()
    .ConfigureHostBuilder();

builder.Host.AsWebSocketHostBuilder()
    .UseHostedService<WebSocketServer>()
    .UseSession<WebSocketServerSession>()
    .ConfigureServerOptions((ctx, config) => { return config.GetSection("WebSocketServer"); })
    .UsePipelineFilter<WebSocketPipelineFilter>()
    .UseWebSocketMessageHandler(ServerMethods.WebSocketDataPackageHandl)
    .ConfigureHostBuilder();

如果在以上代码中,单独使用udp 服务或者websocket 服务,则都可以正常运行,另外使用udp服务的方式,在多启动一个tcp服务也可以正常运行,但只要websocket与其它服务一起启动,则启动失败

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions