Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Data Duplication #14

@mmacfadden

Description

@mmacfadden

Thanks for your work on this project. It's very helpful! I have run into an odd issue where nectar seems to be duplicating some data. I have provided some code that duplicates the issue.

Here is some of the output. First is some screen captures from Wireshark:

TELNET FRAME 1

Wireshark
Image

Console Output
Image

TELNET FRAME 2

Wireshark
Image

Console Output
Image

In the data it looks like some of the lines are not terminated with \r\n. The next frame seems to have escape code and then the \r\n. But the line in the prior frame seems to be duplicated in the TelnetEvent::Message event.

So for example:

      _________|______|_____  @   @@@@@ @   @   @  _____|______|_________

Is turned into:

     _________|______|_____  @   @@@@@ @   @   @  _____|______|_________      _________|______|_____  @   @@@@@ @   @   @  _____|______|_________\u{1b}[H

Here is a way to duplicate the issue:

use std::error::Error;
use futures_lite::StreamExt;
use futures_util::SinkExt;
use nectar::{event::TelnetEvent, TelnetCodec};
use tokio::net::TcpStream;
use tokio_util::codec::Framed;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let address = "towel.blinkenlights.nl:23";
    let tcp_stream = TcpStream::connect(address).await.unwrap();
    let codec = TelnetCodec::new(2048);
    let mut telnet = Framed::new(tcp_stream, codec);

    let mut count = 0;

    loop {
        if let Some(msg) = telnet.next().await {
            match msg {
                Ok(evt) => {
                    match evt {
                        TelnetEvent::Message(message) => {
                            count = count + 1;
                            println!("{:0>4}{:?}", count, message);

                            if count > 205 {
                                break;
                            }
                        }
                        _ => {
                            println!("unhandled telnet event: {:?}", evt);
                        }
                    }
                }
                Err(err) => {
                    println!("telnet error: {:?}", err);
                }
            }
        } else {
            break;
        }
    }

    telnet.close().await.unwrap();

    Ok(())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions