Skip to content

Latest commit

 

History

History
105 lines (87 loc) · 2.32 KB

README.md

File metadata and controls

105 lines (87 loc) · 2.32 KB

Travis Build Coverage Status

net-pull

Providing idiomatic interfaces of the client & server to implement the net pull-stream.

dependency

<dependency>
    <groupId>com.zmannotes</groupId>
    <artifactId>net-pull</artifactId>
    <version>2.1.3</version>
</dependency>

interfaces

IClient

public interface IClient<T> {

    /**
     * 连接目标服务地址
     * @param ip    ip
     * @param port  端口
     */
    void connect(String ip, int port) ;

    /**
     * 主动断开连接
     */
    void disconnect();

    /**
     * 成功连接到server时的回调函数
     * @param callback 回调函数
     */
    IClient onConnected(Consumer<T> callback);

    /**
     * 连接断开时回调
     * @param callback 回调函数
     */
    IClient onDisconnected(Runnable callback);

    /**
     * 连接发生异常时回调
     * @param callback  回调函数
     */
    IClient onThrowable(Consumer<Throwable> callback);

}

IServer

public interface IServer {

    /**
     * 启动Server,监听端口
     * @param port 监听的端口
     */
    void listen(int port);

    /**
     * 停止server,断开所有连接
     */
    void close();

    /**
     * 有新client接入时,回调callback函数
     *
     * @param callback  回调函数,参数:Integer: 连接唯一id,IDuplex:双工流
     */
    IServer onAccept(BiConsumer<Integer, T> callback);

    /**
     * 连接断开时回调
     * @param callback 回调函数,参数为:connectionId 连接唯一id
     *
     */
    IServer onDisconnect(Consumer<Integer> callback);

    /**
     * server停止成功时回调
     * @param callback 回调函数
     */
    IServer onClosed(Runnable callback);

    /**
     * server运行发生异常时回调
     * @param callback 回调函数
     */
    IServer onThrowable(Consumer<Throwable> callback);

}

example

clientTest
        .onConnected(connectCallback)
        .onDisconnected(disconnectCallback)
        .onThrowable(throwableCallback)
        .connect("ip", 0);