This article explains how to connect to WebSocket on shared hosting when the port is blocked:
Connecting to WebSocket on shared hosting with blocked ports
When deploying your C
ASP.NET application on shared hosting, it can be difficult to establish WebSocket connections without encountering port blocking issues. In this article, we will look at ways to overcome these challenges and connect to the Binance WebSocket API.
Why do port blocking issues occur?
Port blocking occurs when the shared hosting service or security software blocks the use of a specific port. When your application tries to establish a WebSocket connection on port 9443 (the default Binance WebSocket port), it may be blocked by your hosting service or security software, which will cause errors or even crashes.
Connecting to WebSocket Using Shared Hosting
To resolve port blocking issues when connecting to WebSocket, you can use the following methods:
1.
Use a non-standard port
One way to connect to Binance WebSocket is to use a non-standard port that is not blocked by your hosting service or security software. You can do this by using the « –host » option when you run the program:
dotnet run --host ws://stream.binance.com:9444/ws
`
In this example, we are using port 8080 as a non-standard port that is not blocked by our hosting service.
2.
Use a tunneling service
Another way to connect to Binance WebSocket is to use a tunneling service such as [ngrok]( ngrok allows you to make your application accessible online, even if it is running on shared hosting. With ngrok, you can establish a WebSocket connection to Binance WebSocket without facing port blocking issues.
3.
Use a VPN or proxy
If you are still having problems with port blocking, consider using a VPN (virtual private network) or proxy to bypass security software that is blocking your application’s port. You can use a VPN service such as [VPNspyne]( or set up a proxy in your hosting environment.
4.
Use WebSockets with a different protocol
If you are still having problems, 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](
5.
Check your hosting documentation
If you are still having trouble connecting to Binance WebSocket, please review your shared hosting documentation to see if it has specific instructions or solutions.
Application
Connecting to WebSocket on shared hosting can be difficult when the port is blocked. However, there are a few methods 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
- Use WebSockets with a different protocol
- Check your hosting service’s documentation
Using one of these methods, you should be able to connect to Binance WebSocket and retrieve token data without encountering port blocking issues.