pub struct KcpEndpoint { /* private fields */ }Implementations§
Source§impl KcpEndpoint
impl KcpEndpoint
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/udp_server.rs (line 11)
10async fn main() {
11 let mut endpoint = KcpEndpoint::new();
12 endpoint.run().await;
13
14 let (input, mut output) = (endpoint.input_sender(), endpoint.output_receiver().unwrap());
15
16 let udp_socket = Arc::new(UdpSocket::bind("0.0.0.0:54321").await.unwrap());
17 udp_socket.connect("127.0.0.1:54320").await.unwrap();
18
19 let udp = udp_socket.clone();
20 tokio::spawn(async move {
21 while let Some(data) = output.recv().await {
22 udp.send(&data.inner()).await.unwrap();
23 }
24 });
25
26 let udp = udp_socket.clone();
27 tokio::spawn(async move {
28 loop {
29 let mut buf = vec![0; 1024];
30 let (size, _) = udp.recv_from(&mut buf).await.unwrap();
31 input
32 .send(BytesMut::from(&buf[..size]).into())
33 .await
34 .unwrap();
35 }
36 });
37
38 loop {
39 let conn_id = endpoint.accept().await.unwrap();
40 let mut kcp_stream = KcpStream::new(&endpoint, conn_id).unwrap();
41
42 let mut buf = vec![0; 64 * 1024];
43 let size = kcp_stream.read(&mut buf).await.unwrap();
44 println!("server recv {}", String::from_utf8_lossy(&buf[..size]));
45
46 kcp_stream.write_all(&buf[..size]).await.unwrap();
47 kcp_stream.flush().await.unwrap();
48 }
49}More examples
examples/udp_client.rs (line 15)
14async fn main() {
15 let mut endpoint = KcpEndpoint::new();
16 endpoint.run().await;
17
18 let (input, mut output) = (endpoint.input_sender(), endpoint.output_receiver().unwrap());
19
20 let udp_socket = Arc::new(UdpSocket::bind("0.0.0.0:54320").await.unwrap());
21 udp_socket.connect("127.0.0.1:54321").await.unwrap();
22
23 let udp = udp_socket.clone();
24 tokio::spawn(async move {
25 while let Some(data) = output.recv().await {
26 udp.send(&data.inner()).await.unwrap();
27 }
28 });
29
30 let udp = udp_socket.clone();
31 tokio::spawn(async move {
32 loop {
33 let mut buf = vec![0; 1024];
34 let (size, _) = udp.recv_from(&mut buf).await.unwrap();
35 input
36 .send(BytesMut::from(&buf[..size]).into())
37 .await
38 .unwrap();
39 }
40 });
41
42 loop {
43 let conn_id = endpoint
44 .connect(Duration::from_secs(1), 0, 0, Bytes::new())
45 .await
46 .unwrap();
47
48 let mut kcp_stream = KcpStream::new(&endpoint, conn_id).unwrap();
49 kcp_stream.write_all(b"hello world").await.unwrap();
50 kcp_stream.flush().await.unwrap();
51
52 let mut buf = vec![0; 64 * 1024];
53 let size = kcp_stream.read(&mut buf).await.unwrap();
54
55 println!("{}", String::from_utf8_lossy(&buf[..size]));
56 tokio::time::sleep(Duration::from_secs(1)).await;
57 }
58}pub fn set_kcp_config_factory(&mut self, factory: KcpConfigFactory)
Sourcepub async fn run(&mut self)
pub async fn run(&mut self)
Examples found in repository?
examples/udp_server.rs (line 12)
10async fn main() {
11 let mut endpoint = KcpEndpoint::new();
12 endpoint.run().await;
13
14 let (input, mut output) = (endpoint.input_sender(), endpoint.output_receiver().unwrap());
15
16 let udp_socket = Arc::new(UdpSocket::bind("0.0.0.0:54321").await.unwrap());
17 udp_socket.connect("127.0.0.1:54320").await.unwrap();
18
19 let udp = udp_socket.clone();
20 tokio::spawn(async move {
21 while let Some(data) = output.recv().await {
22 udp.send(&data.inner()).await.unwrap();
23 }
24 });
25
26 let udp = udp_socket.clone();
27 tokio::spawn(async move {
28 loop {
29 let mut buf = vec![0; 1024];
30 let (size, _) = udp.recv_from(&mut buf).await.unwrap();
31 input
32 .send(BytesMut::from(&buf[..size]).into())
33 .await
34 .unwrap();
35 }
36 });
37
38 loop {
39 let conn_id = endpoint.accept().await.unwrap();
40 let mut kcp_stream = KcpStream::new(&endpoint, conn_id).unwrap();
41
42 let mut buf = vec![0; 64 * 1024];
43 let size = kcp_stream.read(&mut buf).await.unwrap();
44 println!("server recv {}", String::from_utf8_lossy(&buf[..size]));
45
46 kcp_stream.write_all(&buf[..size]).await.unwrap();
47 kcp_stream.flush().await.unwrap();
48 }
49}More examples
examples/udp_client.rs (line 16)
14async fn main() {
15 let mut endpoint = KcpEndpoint::new();
16 endpoint.run().await;
17
18 let (input, mut output) = (endpoint.input_sender(), endpoint.output_receiver().unwrap());
19
20 let udp_socket = Arc::new(UdpSocket::bind("0.0.0.0:54320").await.unwrap());
21 udp_socket.connect("127.0.0.1:54321").await.unwrap();
22
23 let udp = udp_socket.clone();
24 tokio::spawn(async move {
25 while let Some(data) = output.recv().await {
26 udp.send(&data.inner()).await.unwrap();
27 }
28 });
29
30 let udp = udp_socket.clone();
31 tokio::spawn(async move {
32 loop {
33 let mut buf = vec![0; 1024];
34 let (size, _) = udp.recv_from(&mut buf).await.unwrap();
35 input
36 .send(BytesMut::from(&buf[..size]).into())
37 .await
38 .unwrap();
39 }
40 });
41
42 loop {
43 let conn_id = endpoint
44 .connect(Duration::from_secs(1), 0, 0, Bytes::new())
45 .await
46 .unwrap();
47
48 let mut kcp_stream = KcpStream::new(&endpoint, conn_id).unwrap();
49 kcp_stream.write_all(b"hello world").await.unwrap();
50 kcp_stream.flush().await.unwrap();
51
52 let mut buf = vec![0; 64 * 1024];
53 let size = kcp_stream.read(&mut buf).await.unwrap();
54
55 println!("{}", String::from_utf8_lossy(&buf[..size]));
56 tokio::time::sleep(Duration::from_secs(1)).await;
57 }
58}Sourcepub fn output_receiver(&mut self) -> Option<KcpPacketReceiver>
pub fn output_receiver(&mut self) -> Option<KcpPacketReceiver>
Examples found in repository?
examples/udp_server.rs (line 14)
10async fn main() {
11 let mut endpoint = KcpEndpoint::new();
12 endpoint.run().await;
13
14 let (input, mut output) = (endpoint.input_sender(), endpoint.output_receiver().unwrap());
15
16 let udp_socket = Arc::new(UdpSocket::bind("0.0.0.0:54321").await.unwrap());
17 udp_socket.connect("127.0.0.1:54320").await.unwrap();
18
19 let udp = udp_socket.clone();
20 tokio::spawn(async move {
21 while let Some(data) = output.recv().await {
22 udp.send(&data.inner()).await.unwrap();
23 }
24 });
25
26 let udp = udp_socket.clone();
27 tokio::spawn(async move {
28 loop {
29 let mut buf = vec![0; 1024];
30 let (size, _) = udp.recv_from(&mut buf).await.unwrap();
31 input
32 .send(BytesMut::from(&buf[..size]).into())
33 .await
34 .unwrap();
35 }
36 });
37
38 loop {
39 let conn_id = endpoint.accept().await.unwrap();
40 let mut kcp_stream = KcpStream::new(&endpoint, conn_id).unwrap();
41
42 let mut buf = vec![0; 64 * 1024];
43 let size = kcp_stream.read(&mut buf).await.unwrap();
44 println!("server recv {}", String::from_utf8_lossy(&buf[..size]));
45
46 kcp_stream.write_all(&buf[..size]).await.unwrap();
47 kcp_stream.flush().await.unwrap();
48 }
49}More examples
examples/udp_client.rs (line 18)
14async fn main() {
15 let mut endpoint = KcpEndpoint::new();
16 endpoint.run().await;
17
18 let (input, mut output) = (endpoint.input_sender(), endpoint.output_receiver().unwrap());
19
20 let udp_socket = Arc::new(UdpSocket::bind("0.0.0.0:54320").await.unwrap());
21 udp_socket.connect("127.0.0.1:54321").await.unwrap();
22
23 let udp = udp_socket.clone();
24 tokio::spawn(async move {
25 while let Some(data) = output.recv().await {
26 udp.send(&data.inner()).await.unwrap();
27 }
28 });
29
30 let udp = udp_socket.clone();
31 tokio::spawn(async move {
32 loop {
33 let mut buf = vec![0; 1024];
34 let (size, _) = udp.recv_from(&mut buf).await.unwrap();
35 input
36 .send(BytesMut::from(&buf[..size]).into())
37 .await
38 .unwrap();
39 }
40 });
41
42 loop {
43 let conn_id = endpoint
44 .connect(Duration::from_secs(1), 0, 0, Bytes::new())
45 .await
46 .unwrap();
47
48 let mut kcp_stream = KcpStream::new(&endpoint, conn_id).unwrap();
49 kcp_stream.write_all(b"hello world").await.unwrap();
50 kcp_stream.flush().await.unwrap();
51
52 let mut buf = vec![0; 64 * 1024];
53 let size = kcp_stream.read(&mut buf).await.unwrap();
54
55 println!("{}", String::from_utf8_lossy(&buf[..size]));
56 tokio::time::sleep(Duration::from_secs(1)).await;
57 }
58}Sourcepub fn input_sender(&self) -> KcpPakcetSender
pub fn input_sender(&self) -> KcpPakcetSender
Examples found in repository?
examples/udp_server.rs (line 14)
10async fn main() {
11 let mut endpoint = KcpEndpoint::new();
12 endpoint.run().await;
13
14 let (input, mut output) = (endpoint.input_sender(), endpoint.output_receiver().unwrap());
15
16 let udp_socket = Arc::new(UdpSocket::bind("0.0.0.0:54321").await.unwrap());
17 udp_socket.connect("127.0.0.1:54320").await.unwrap();
18
19 let udp = udp_socket.clone();
20 tokio::spawn(async move {
21 while let Some(data) = output.recv().await {
22 udp.send(&data.inner()).await.unwrap();
23 }
24 });
25
26 let udp = udp_socket.clone();
27 tokio::spawn(async move {
28 loop {
29 let mut buf = vec![0; 1024];
30 let (size, _) = udp.recv_from(&mut buf).await.unwrap();
31 input
32 .send(BytesMut::from(&buf[..size]).into())
33 .await
34 .unwrap();
35 }
36 });
37
38 loop {
39 let conn_id = endpoint.accept().await.unwrap();
40 let mut kcp_stream = KcpStream::new(&endpoint, conn_id).unwrap();
41
42 let mut buf = vec![0; 64 * 1024];
43 let size = kcp_stream.read(&mut buf).await.unwrap();
44 println!("server recv {}", String::from_utf8_lossy(&buf[..size]));
45
46 kcp_stream.write_all(&buf[..size]).await.unwrap();
47 kcp_stream.flush().await.unwrap();
48 }
49}More examples
examples/udp_client.rs (line 18)
14async fn main() {
15 let mut endpoint = KcpEndpoint::new();
16 endpoint.run().await;
17
18 let (input, mut output) = (endpoint.input_sender(), endpoint.output_receiver().unwrap());
19
20 let udp_socket = Arc::new(UdpSocket::bind("0.0.0.0:54320").await.unwrap());
21 udp_socket.connect("127.0.0.1:54321").await.unwrap();
22
23 let udp = udp_socket.clone();
24 tokio::spawn(async move {
25 while let Some(data) = output.recv().await {
26 udp.send(&data.inner()).await.unwrap();
27 }
28 });
29
30 let udp = udp_socket.clone();
31 tokio::spawn(async move {
32 loop {
33 let mut buf = vec![0; 1024];
34 let (size, _) = udp.recv_from(&mut buf).await.unwrap();
35 input
36 .send(BytesMut::from(&buf[..size]).into())
37 .await
38 .unwrap();
39 }
40 });
41
42 loop {
43 let conn_id = endpoint
44 .connect(Duration::from_secs(1), 0, 0, Bytes::new())
45 .await
46 .unwrap();
47
48 let mut kcp_stream = KcpStream::new(&endpoint, conn_id).unwrap();
49 kcp_stream.write_all(b"hello world").await.unwrap();
50 kcp_stream.flush().await.unwrap();
51
52 let mut buf = vec![0; 64 * 1024];
53 let size = kcp_stream.read(&mut buf).await.unwrap();
54
55 println!("{}", String::from_utf8_lossy(&buf[..size]));
56 tokio::time::sleep(Duration::from_secs(1)).await;
57 }
58}pub fn input_sender_ref(&self) -> &KcpPakcetSender
pub fn conn_sender_receiver( &self, conn_id: ConnId, ) -> Option<(KcpStreamSender, KcpStreamReceiver)>
pub fn conn_data(&self, conn_id: &ConnId) -> Option<Bytes>
Sourcepub async fn connect(
&self,
timeout_dur: Duration,
src_session_id: u32,
dst_session_id: u32,
conn_data: Bytes,
) -> Result<ConnId, Error>
pub async fn connect( &self, timeout_dur: Duration, src_session_id: u32, dst_session_id: u32, conn_data: Bytes, ) -> Result<ConnId, Error>
Examples found in repository?
examples/udp_client.rs (line 44)
14async fn main() {
15 let mut endpoint = KcpEndpoint::new();
16 endpoint.run().await;
17
18 let (input, mut output) = (endpoint.input_sender(), endpoint.output_receiver().unwrap());
19
20 let udp_socket = Arc::new(UdpSocket::bind("0.0.0.0:54320").await.unwrap());
21 udp_socket.connect("127.0.0.1:54321").await.unwrap();
22
23 let udp = udp_socket.clone();
24 tokio::spawn(async move {
25 while let Some(data) = output.recv().await {
26 udp.send(&data.inner()).await.unwrap();
27 }
28 });
29
30 let udp = udp_socket.clone();
31 tokio::spawn(async move {
32 loop {
33 let mut buf = vec![0; 1024];
34 let (size, _) = udp.recv_from(&mut buf).await.unwrap();
35 input
36 .send(BytesMut::from(&buf[..size]).into())
37 .await
38 .unwrap();
39 }
40 });
41
42 loop {
43 let conn_id = endpoint
44 .connect(Duration::from_secs(1), 0, 0, Bytes::new())
45 .await
46 .unwrap();
47
48 let mut kcp_stream = KcpStream::new(&endpoint, conn_id).unwrap();
49 kcp_stream.write_all(b"hello world").await.unwrap();
50 kcp_stream.flush().await.unwrap();
51
52 let mut buf = vec![0; 64 * 1024];
53 let size = kcp_stream.read(&mut buf).await.unwrap();
54
55 println!("{}", String::from_utf8_lossy(&buf[..size]));
56 tokio::time::sleep(Duration::from_secs(1)).await;
57 }
58}Sourcepub async fn accept(&self) -> Result<ConnId, Error>
pub async fn accept(&self) -> Result<ConnId, Error>
Examples found in repository?
examples/udp_server.rs (line 39)
10async fn main() {
11 let mut endpoint = KcpEndpoint::new();
12 endpoint.run().await;
13
14 let (input, mut output) = (endpoint.input_sender(), endpoint.output_receiver().unwrap());
15
16 let udp_socket = Arc::new(UdpSocket::bind("0.0.0.0:54321").await.unwrap());
17 udp_socket.connect("127.0.0.1:54320").await.unwrap();
18
19 let udp = udp_socket.clone();
20 tokio::spawn(async move {
21 while let Some(data) = output.recv().await {
22 udp.send(&data.inner()).await.unwrap();
23 }
24 });
25
26 let udp = udp_socket.clone();
27 tokio::spawn(async move {
28 loop {
29 let mut buf = vec![0; 1024];
30 let (size, _) = udp.recv_from(&mut buf).await.unwrap();
31 input
32 .send(BytesMut::from(&buf[..size]).into())
33 .await
34 .unwrap();
35 }
36 });
37
38 loop {
39 let conn_id = endpoint.accept().await.unwrap();
40 let mut kcp_stream = KcpStream::new(&endpoint, conn_id).unwrap();
41
42 let mut buf = vec![0; 64 * 1024];
43 let size = kcp_stream.read(&mut buf).await.unwrap();
44 println!("server recv {}", String::from_utf8_lossy(&buf[..size]));
45
46 kcp_stream.write_all(&buf[..size]).await.unwrap();
47 kcp_stream.flush().await.unwrap();
48 }
49}Trait Implementations§
Auto Trait Implementations§
impl Freeze for KcpEndpoint
impl !RefUnwindSafe for KcpEndpoint
impl Send for KcpEndpoint
impl Sync for KcpEndpoint
impl Unpin for KcpEndpoint
impl !UnwindSafe for KcpEndpoint
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more