Add dependencies

This commit is contained in:
Changhua 2023-03-19 09:12:44 +08:00
parent 0e3273152b
commit dd467673c7
7 changed files with 20263 additions and 8 deletions

View File

@ -10,10 +10,13 @@ repositories {
}
dependencies {
implementation 'com.google.protobuf:protobuf-java:3.22.2'
implementation 'net.java.dev.jna:jna:5.6.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
test {
useJUnitPlatform()
}
}

Binary file not shown.

View File

@ -0,0 +1,62 @@
package com.iamteer;
import com.iamteer.Wcf.Functions;
import com.iamteer.Wcf.Request;
import com.iamteer.Wcf.Response;
import io.sisu.nng.Socket;
import io.sisu.nng.pair.Pair1Socket;
import java.nio.ByteBuffer;
import java.util.Arrays;
public class Client {
private final int BUFFER_SIZE = 16 * 1024 * 1024; // 16M
private Socket socket = null;
public Client(String hostPort) {
connectRPC(hostPort);
}
private void connectRPC(String url) {
try {
socket = new Pair1Socket();
socket.dial(url);
while (!isLogin()) { // 直到登录成功
waitMs(1000);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
public boolean isLogin() {
Request req = new Request.Builder().setFuncValue(Functions.FUNC_IS_LOGIN_VALUE).build();
Response rsp = sendCmd(req);
if (rsp != null) {
return rsp.getStatus() == 1;
}
return false;
}
public void waitMs(int ms) {
try {
Thread.sleep(ms);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
private Response sendCmd(Request req) {
try {
ByteBuffer bb = ByteBuffer.wrap(req.toByteArray());
socket.send(bb);
ByteBuffer ret = ByteBuffer.allocate(BUFFER_SIZE);
long size = socket.receive(ret, true);
return Response.parseFrom(Arrays.copyOfRange(ret.array(), 0, (int) size));
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

View File

@ -0,0 +1,10 @@
package com.iamteer;
public class Main {
public static void main(String[] args) {
final String url = "tcp://192.168.1.104:10086";
Client client = new Client(url);
System.out.println("IsLogin: " + client.isLogin());
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +0,0 @@
package org.example;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}

Binary file not shown.