7 months ago
I am running a Go service via Docker locally, and the WebSocket connection works fine. However, when I deploy it to the cloud, I get a "bad handshake" error using the same method.
I use this:
https://bybit-exchange.github.io/docs/v5/ws/connect
ⓘ Deployment information is only viewable by project members and Railway employees.
3 Replies
7 months ago
// Connect establishes a WebSocket connection.
func (client *BybitWebSocketClient) Connect() error {
logrus.Info("Attempting to connect to WebSocket server...")
conn, resp, err := websocket.DefaultDialer.Dial(client.url, nil)
if err != nil {
if resp != nil {
logrus.WithFields(logrus.Fields{
"status": resp.StatusCode,
"headers": resp.Header,
"body": resp.Body,
}).Error("Failed to connect to WebSocket server")
} else {
logrus.WithError(err).Error("Failed to connect to WebSocket server")
}
return fmt.Errorf("failed to connect: %w", err)
}
websocket.DefaultDialer.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
}
client.conn = conn
logrus.Info(" Successfully connected to WebSocket server")
return nil
}
wsclient := ws.NewWebSocketClient(cfg.BYBITWSURL)
if err := wsclient.Connect(); err != nil {
logrus.Fatalf("Failed to connect: %v", err)
}
defer func(wsclient *ws.BybitWebSocketClient) {
err := wsclient.Close()
if err != nil {
logrus.Fatalf("Failed to close: %v", err)
}
}(wsclient)
Executing: /go/bin/trade wsclient
Init logging
Starting a ws client listener
Attempting to connect to WebSocket server...
Failed to connect: failed to connect: websocket: bad handshake
7 months ago
"<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <TITLE>ERROR: The request could not be satisfied</TITLE> </HEAD><BODY> <H1>403 ERROR</H1> <H2>The request could not be satisfied.</H2> <HR noshade size="1px"> The Amazon CloudFront distribution is configured to block access from your country. We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner. <BR clear="all"> If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation. <BR clear="all"> <HR noshade size="1px"> <PRE> Generated by cloudfront (CloudFront) Request ID: d8r8-M4iiEZiFfEw7A6MxFhbo1zKRuCbA07lGsZGgwWXtRY87AnL9w== </PRE> <ADDRESS> </ADDRESS> </BODY></HTML>"
7 months ago
Make sure you're using wss
instead of ws
when the websocket server is running on Railway
Status changed to Solved dev • 7 months ago