Code Monkey home page Code Monkey logo

kcp's People

Contributors

matrix-zhang avatar raintean avatar realshell avatar s1rius avatar zonyitoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kcp's Issues

Async write for Kcp Struct

Currently Kcp struct requires Write which makes integration with DTLS a little hard (since send_to is async rather than sync) so what can we do to deal with this situation?

Test code error

rcp2 never echos back, maybe there is something wrong with the “peer” in the “LatencySimulator::recv"

After reading data 128 times, kcp.recv will report an error

Errvalue: RecvQueueEmptyusize 123
usize 124
usize 125
usize 126
usize 127
usize 128
thread 'main' panicked at src/bin/conn2.rs:36:42:
called Result::unwrap() on an Err value: RecvQueueEmpty`

I have conducted a simple investigation and it should be related to "const KCP_WND.RCV: u16=128;//must>=max fragment size", but this should not be an error. Is there a method to set it? I tried to modify this value to 500 The number of reads can exceed 128, but this should not be the method to fix this problem. At the same time, we also encountered a new issue where "kcp. set_wndsize (256, 256);" still outputs the same error at 256.

I wonder if I need to set certain values to avoid this issue, or if this is an unnoticed error?

No data output after flush

Call kcp.send() and kcp.flush() twice, the first call get output, but the second call get nothing.

use std::{sync::{Arc, Mutex}, collections::VecDeque};

use ::kcp::Kcp;

#[test]
fn test_kcp() {
    let output = MockOutput::default();
    let mut kcp = Kcp::new(123, output.clone());
    
    kcp.update(now_millis()).unwrap();
    

    let r = kcp.send("abc".as_bytes()).unwrap();
    assert_eq!(r, 3);

    let r = output.pop_front();
    assert_eq!(r.is_some(), false, "{r:?}");
    
    let _r = kcp.flush().unwrap();
    let r = output.pop_front();
    assert_eq!(r.is_some(), true, "{r:?}");
    

    let r = kcp.send("def".as_bytes()).unwrap();
    assert_eq!(r, 3);

    let r = output.pop_front();
    assert_eq!(r.is_some(), false, "{r:?}");

    let _r = kcp.flush().unwrap();
    let r = output.pop_front();
    assert_eq!(r.is_some(), true, "{r:?}");   // <== panicked at here !!!!!!
}

#[derive(Default, Clone)]
struct MockOutput {
    que: Arc<Mutex<VecDeque<WriteOp>>>
}

impl MockOutput {
    fn pop_front(&self) -> Option<WriteOp> {
        self.que.lock().unwrap().pop_front()
    }
}

impl std::io::Write for MockOutput {
    fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
        self.que.lock().unwrap().push_back(WriteOp::Write(Vec::from(buf)));
        Ok(buf.len())
    }

    fn flush(&mut self) -> std::io::Result<()> {
        self.que.lock().unwrap().push_back(WriteOp::Flush);
        Ok(())
    }
}

#[derive(Debug)]
enum WriteOp {
    Write(Vec<u8>),
    Flush,
}

#[inline]
pub fn now_millis() -> u32 {
    let start = std::time::SystemTime::now();
    let since_the_epoch = start.duration_since(std::time::UNIX_EPOCH).expect("time went afterwards");
    // (since_the_epoch.as_secs() * 1000 + since_the_epoch.subsec_millis() as u64) as u32
    since_the_epoch.as_millis() as u32
}

Advise

Hi,

Thanks for the crate.
Is that advisable for 500 bytes of data average? Is it as reliable as TCP in term of delivery (not order).

Can you provide an example of associating "std:: net:: UdpSocket"?

Thank you very much for your project, but I have referred to many different codes and still don't understand how to associate it with "std:: net:: UdpSocket". If your time permits and you are willing to provide a simple association to "std:: net:: UdpSocket", it will be of great help to me! Thank you again!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.