Open arthasyou opened 3 weeks ago
Supplementary Information:
To provide further context for my issue with binance_spot_connector_rust
, I wrote a simple Go program that successfully connects to the Binance WebSocket endpoint and receives data without any issues. Here is the Go code:
package main
import (
"log"
"github.com/gorilla/websocket"
)
func main() {
// WebSocket服务器地址
url := "wss://stream.binance.com:443/ws/btcusdt@miniTicker"
// 连接WebSocket服务器
c, _, err := websocket.DefaultDialer.Dial(url, nil)
if err != nil {
log.Fatal("连接失败:", err)
}
defer c.Close()
done := make(chan struct{})
// 处理接收消息
defer close(done)
for i := 0; i < 10; i++ {
_, message, err := c.ReadMessage()
if err != nil {
log.Println("读取消息错误:", err)
return
}
log.Printf("收到消息: %s", message)
}
}
Observation:
wss://stream.binance.com:443/ws/btcusdt@miniTicker
and receives data as expected.Comparison with Rust:
binance_spot_connector_rust
to establish the same connection in Rust, the connection attempt hangs and eventually times out, suggesting a potential issue with the Rust implementation or library.Request:
I would appreciate any guidance or insight into why the Go implementation succeeds while the Rust code using binance_spot_connector_rust
fails to establish a connection and times out. Any recommendations for resolving this discrepancy would be greatly appreciated.
I am facing an issue with a simple Rust program using the tungstenite
crate to connect to a WebSocket server. The connection attempt fails, and the expected output line confirming the connection does not print. Here is the code snippet:
use tungstenite::{connect, Message};
use url::Url;
fn main() {
// WebSocket server address
let url = "wss://stream.binance.com:443/ws/btcusdt@miniTicker";
// Connect to the WebSocket server
let (mut socket, response) = connect(Url::parse(url).unwrap()).expect("Connection failed");
println!(
"Connection successful, HTTP status code: {}",
response.status()
);
// Receive and print messages
for _ in 0..10 {
let msg = socket.read().expect("Failed to read message");
match msg {
Message::Text(text) => {
println!("Received message: {}", text);
}
Message::Ping(ping) => {
println!("Received Ping: {:?}", ping);
// Respond with Pong
socket
.send(Message::Pong(ping))
.expect("Failed to send Pong");
}
Message::Close(frame) => {
println!("Connection closed: {:?}", frame);
break;
}
_ => (),
}
}
// Close the connection
socket.close(None).expect("Failed to close connection");
}
Observation:
println!("Connection successful, HTTP status code: {}", response.status());
does not print, which suggests that the connection is not established.expect("Connection failed")
does not panic, indicating the issue might occur after the initial connection attempt or during the handshake.Expected Behavior: The program should print the HTTP status code after establishing a successful connection and proceed to read and print messages from the WebSocket server.
Actual Behavior: The connection attempt does not produce any output related to a successful connection, suggesting that the connection is not being completed or is failing silently.
Environment:
tungstenite
version: 0.24url
version: 2.5Relevant Cargo.toml
Configuration:
[dependencies]
tungstenite = { version = "0.24", features = ["native-tls", "url"] }
url = "2.5"
Additional Information:
Request:
I am looking for assistance in diagnosing why the connection using tungstenite
does not succeed and does not print the expected line indicating connection success. Any insights into potential issues or required configurations would be greatly appreciated.
example/tokio_tungstenite.rs
I am facing an issue with the
binance_spot_connector_rust
library where the WebSocket connection attempt times out without any response. When executing the following code:the connection hangs and eventually results in a timeout error.
Steps to Reproduce:
binance_spot_connector_rust
crate to create a WebSocket connection to Binance.wss://stream.binance.com:9443/ws/btcusdt@miniTicker
.connect_async
.Expected Behavior: The connection should be established successfully and proceed to receive messages from the WebSocket stream.
Actual Behavior: The connection hangs indefinitely without any response, and after a while, a timeout error occurs.
Environment:
binance_spot_connector_rust
version: [Insert version]Additional Information:
I would appreciate any guidance on why the connection might be timing out and suggestions for potential fixes. Thank you!