Fixed issue with weird tcp packets
This commit is contained in:
parent
8966a25e8d
commit
c037e2d2a1
@ -70,7 +70,6 @@ async fn register_tcp(args: Args) -> Result<()> {
|
||||
}
|
||||
|
||||
async fn tcp_connection(stream: TcpStream, tx: Sender<OscPacket>) -> Result<()> {
|
||||
println!("Accepted new Carla TCP connection");
|
||||
let mut buf = vec![0; 1024];
|
||||
let mut stream = stream;
|
||||
|
||||
@ -78,7 +77,13 @@ async fn tcp_connection(stream: TcpStream, tx: Sender<OscPacket>) -> Result<()>
|
||||
let bytes = stream.read(&mut buf).await?;
|
||||
let packet = &buf[0..bytes];
|
||||
if bytes > 4 {
|
||||
let (_, packet) = decode_udp(packet)?;
|
||||
let len_bytes = [buf[0], buf[1], buf[2], buf[3]];
|
||||
let len = u32::from_be_bytes(len_bytes) as usize;
|
||||
let packet = if len == bytes - 4 {
|
||||
decode_udp(&packet[4..bytes])?.1
|
||||
} else {
|
||||
decode_udp(packet)?.1
|
||||
};
|
||||
tx.send(packet).await?;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user