Here's an article explaining how to connect to WebSockets on shared hosting when a port is blocked:
Connecting to Websocket on Shared Hosting with Blocked Ports
When you deploy your C
ASP.NET application to shared hosting, it can be challenging to run WebSocket connections without encountering port blocking issues. In this article, we'll explore ways to overcome these challenges and connect to the Binance WebSocket API.
Why Port Blocking Issues?
Port blocking occurs when a shared hosting service or security software blocks a specific port from being used. When your application tries to establish a WebSocket connection on port 9443 (the default port for Binance WebSocket), it may be blocked by the hosting service or security software, resulting in errors or even crashes.
Connecting to Websocket on Shared Hosting
To overcome port blocking issues when connecting to WebSockets, you can use the following techniques:
1.
Use a non-standard port
One way to connect to Binance WebSocket is to use a non-standard port that's not blocked by your hosting service or security software. You can do this by using the --host
option when running your application:
dotnet run --host ws://stream.binance.com:9444/ws
In this example, we're using port 8080 as a non-standard port that's not blocked by our hosting service.
2.
Use a tunneling service
Another way to connect to Binance WebSocket is through the use of a tunneling service like [ngrok]( ngrok allows you to expose your application to the internet, even if it's running on shared hosting. By using ngrok, you can establish a WebSocket connection to Binance WebSocket without encountering port blocking issues.
3.
Use a VPN or proxy server
If you're still experiencing port blocking issues, consider using a VPN (Virtual Private Network) or proxy server to bypass the security software blocking your application's port. You can use a VPN service like [VPNspyne]( or set up a proxy server in your hosting environment.
4.
Use WebSockets with a different protocol
If you're still having trouble, consider using WebSockets with a different protocol. Binance WebSocket uses the ws
protocol, which is not blocked by some security software. You can try using a WebSocket library that supports this protocol, such as [websocket-net]( websocket-net/ws).
5.
Check your hosting service's documentation
If you're still having trouble connecting to Binance WebSocket, check the documentation for your shared hosting service to see if they have any specific instructions or workarounds.
Conclusion
Connecting to WebSockets on shared hosting can be challenging when a port is blocked. However, there are several techniques you can use to overcome these challenges and establish a WebSocket connection with Binance WebSocket:
- Use a non-standard port
- Use a tunneling service like ngrok
- Use a VPN or proxy server
- Use WebSockets with a different protocol
- Check your hosting service's documentation
By using one of these techniques, you should be able to connect to Binance WebSocket and retrieve ticker data without encountering port blocking issues.