Skip to content

yanglangfei/AndroidSocketClient

 
 

Repository files navigation

AndroidSocketClient

socket client server简易封装

Import

JitPack

Add it in your project's build.gradle at the end of repositories:

repositories {
  // ...
  maven { url "https://jitpack.io" }
}

Step 2. Add the dependency in the form

dependencies {
  compile 'com.github.vilyever:AndroidSocketClient:1.2.4'
}

Notice

使用SocketClient接收消息时,是通过readLine的方式进行,即每一条消息为一行,故远程端发送的消息需在末尾加上换行符 '\n '或 '\r\n'
使用SocketClient和SocketServer发送的String消息会自动在末尾添加 '\r\n' 换行符

Usage

SocketClient socketClient = new SocketClient("192.168.1.1", 80);
socketClient.registerSocketDelegate(new SocketClient.SocketDelegate() {
    @Override
    public void onConnected(SocketClient client) {

    }

    @Override
    public void onDisconnected(SocketClient client) {

    }

    @Override
    public void onResponse(SocketClient client, @NonNull String response) {

    }
});

socketClient.connect();

License

Apache License Version 2.0

About

socket client 简易封装

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%