JKorf / HTX.Net

A C# .netstandard client library for the Huobi REST and Websocket Spot and Swap API focusing on clear usage and models
https://jkorf.github.io/HTX.Net/
MIT License
73 stars 53 forks source link

WebSocket connection can't be established while in Docker container #107

Open iTKerry opened 6 months ago

iTKerry commented 6 months ago

Describe the bug I packed an ASP.NET application that consumes HuobiSocketClient into Docker image and hosted it locally using docker-compose. The same code works well outside of Docker. Also, REST API forks well from Docker. The issue is only with WSS connection.

Same approach work successfully with other exchanges from CryptoExchange.Net EXCEPT: Huobi, Kucoin, OKX

To Reproduce

Just try to establish socket connection from Docker container.

docker-compose.yml

  huobi.server:
    container_name: huobi.server
    build:
      context: .
      dockerfile: ./MyProjectName/Dockerfile
    ports:
      - "5006:5006"
    environment:
      - "ASPNETCORE_ENVIRONMENT=Production"
      - "ASPNETCORE_URLS=http://+:5006"
    networks:
      - customNetwork

Some code from program.cs

var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel(options => options.ListenAnyIP(5006, o => o.Protocols = HttpProtocols.Http1AndHttp2AndHttp3));

var app = builder.Build();
app.UseWebSockets();
app.Run();

Expected behavior Connection should be established successfully.

Debug logging Error while establishing connection: {"Code":null,"Message":"Can't connect to the server","Data":null}