Add dependencies
This commit is contained in:
parent
0e3273152b
commit
dd467673c7
@ -10,6 +10,9 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
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'
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
|
||||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
|
||||||
}
|
}
|
||||||
|
BIN
java/wcferry/libs/nng-java-1.4.0-SNAPSHOT.jar
Normal file
BIN
java/wcferry/libs/nng-java-1.4.0-SNAPSHOT.jar
Normal file
Binary file not shown.
62
java/wcferry/src/main/java/com/iamteer/Client.java
Normal file
62
java/wcferry/src/main/java/com/iamteer/Client.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
java/wcferry/src/main/java/com/iamteer/Main.java
Normal file
10
java/wcferry/src/main/java/com/iamteer/Main.java
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
20187
java/wcferry/src/main/java/com/iamteer/Wcf.java
Normal file
20187
java/wcferry/src/main/java/com/iamteer/Wcf.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,7 +0,0 @@
|
|||||||
package org.example;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
System.out.println("Hello world!");
|
|
||||||
}
|
|
||||||
}
|
|
BIN
java/wcferry/src/main/resources/win32-x86-64/nng.dll
Normal file
BIN
java/wcferry/src/main/resources/win32-x86-64/nng.dll
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user