Topics

Forum Topics not found

Replies

DevChris
18 Aug 2023, 15:25 ( Updated at: 18 Aug 2023, 15:31 )

Same problem today using rust with tokio::TcpStream with tokio_openssl::SslStream,

the code:

 println!("connecting to server: {:?}", PROTOBUF_DEMO_ENDPOINT);
    let stream = TcpStream::connect(&PROTOBUF_DEMO_ENDPOINT).await?;
    println!("connected to server: {:?}", stream.peer_addr()?);
    let conn_builder = SslConnector::builder(SslMethod::tls())?;
    let mut conn_config = conn_builder.build().configure()?;
    // conn_config.set_max_proto_version(Some(SslVersion::TLS1_1))?;
    // conn_config.set_verify(SslVerifyMode::NONE);
    let ssl = conn_config.into_ssl("ctraderapi.com")?;
    println!("ssl: {}", ssl.version_str());
    let mut stream = SslStream::new(ssl, stream).unwrap();
    Pin::new(&mut stream).connect().await.unwrap();

    let mut app_auth = ProtoOaApplicationAuthReq::default();
    app_auth.client_id = CLIENT_ID.to_string();
    app_auth.client_secret = CLIENT_SECRET.to_string();
    let buf = serialize(&app_auth);
    println!("sending app auth ({})", buf.len());
    stream.write_all(&buf).await.unwrap();

    let mut buf = Vec::new();
    buf.resize(4096, 0);
    let data = stream.read(&mut buf).await.unwrap();
    println!("received {} bytes", data);
    println!("buf: {:?}", &buf[..data]);

    let str = String::from_utf8_lossy(&buf[..data]);
    println!("str: {}", str);

the logs:

connecting to server: "demo.ctraderapi.com:5035"
connected to server: 15.197.239.248:5035
ssl: TLSv1.3
sending app auth (113)
received 60 bytes
buf: [0, 0, 0, 56, 8, 222, 16, 18, 51, 26, 14, 70, 82, 65, 77, 69, 95, 84, 79, 79, 95, 76, 79, 78, 71, 34, 33, 70, 114, 97, 109, 101, 32, 115, 105, 122, 101, 32, 101, 120, 99, 101, 101, 100, 115, 32, 97, 108, 108, 111, 119, 101, 100, 32, 108, 105, 109, 105, 116, 46]
str: �3FRAME_TOO_LONG"!Frame size exceeds allowed limit.

@DevChris