[][src]Struct kcpserver::KcpListener

pub struct KcpListener<S, R> where
    S: Send + 'static,
    R: Future<Output = Result<(), Box<dyn Error>>> + Send + 'static, 
{ /* fields omitted */ }

KcpListener 整个KCP 服务的入口点 config 存放KCP 配置 S是用户逻辑上下文类型

Examples Echo

#![feature(async_closure)]
use kcpserver::KcpListener;
use kcpserver::KcpConfig;
use kcpserver::KcpNoDelayConfig;
use std::error::Error;

#[tokio::main]
async fn main()->Result<(),Box<dyn Error>>{
     let mut config = KcpConfig::default();
     config.nodelay = Some(KcpNoDelayConfig::fastest());
     let kcp = KcpListener::<i32, _>::new("0.0.0.0:5555", config).await?;
     kcp.set_buff_input(async move |peer, data| {
         peer.send(&data).await?;
         Ok(())
      }).await;
     kcp.start().await?;
     Ok(())
}

Implementations

impl<S, R> KcpListener<S, R> where
    S: Send + 'static,
    R: Future<Output = Result<(), Box<dyn Error>>> + Send + 'static, 
[src]

pub async fn new<A: ToSocketAddrs>(
    addr: A,
    config: KcpConfig
) -> Result<Arc<Self>, Box<dyn Error>>
[src]

创建一个KCPListener addr 监听的本地地址:端口 config 是KCP的配置

pub async fn set_buff_input<'_>(
    &'_ self,
    f: impl Fn(Arc<KcpPeer<S>>, Bytes) -> R + 'static + Send + Sync
)
[src]

设置数据表输入函数

pub async fn start<'_>(&'_ self) -> Result<(), Box<dyn Error>>[src]

启动服务

Trait Implementations

impl<S, R> Send for KcpListener<S, R> where
    S: Send + 'static,
    R: Future<Output = Result<(), Box<dyn Error>>> + Send + 'static, 
[src]

impl<S, R> Sync for KcpListener<S, R> where
    S: Send + 'static,
    R: Future<Output = Result<(), Box<dyn Error>>> + Send + 'static, 
[src]

Auto Trait Implementations

impl<S, R> !RefUnwindSafe for KcpListener<S, R>

impl<S, R> Unpin for KcpListener<S, R>

impl<S, R> !UnwindSafe for KcpListener<S, R>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.