Adapt new dll

This commit is contained in:
Changhua 2023-04-09 16:20:38 +08:00
parent e46f21a7d4
commit c0708e49d0
2 changed files with 25 additions and 12 deletions

View File

@ -20,28 +20,40 @@ public class Client {
private final int BUFFER_SIZE = 16 * 1024 * 1024; // 16M private final int BUFFER_SIZE = 16 * 1024 * 1024; // 16M
private Socket cmdSocket = null; private Socket cmdSocket = null;
private Socket msgSocket = null; private Socket msgSocket = null;
private String cmdUrl = "tcp://127.0.0.1:10086"; private String host = "127.0.0.1";
private int port = 10086;
private boolean isReceivingMsg = false; private boolean isReceivingMsg = false;
private boolean isLocalHostPort = false; private boolean isLocalHostPort = false;
private BlockingQueue<WxMsg> msgQ; private BlockingQueue<WxMsg> msgQ;
private String wcfPath; private String wcfPath;
public Client(String hostPort) { public Client(String host, int port) {
cmdUrl = hostPort; this.host = host;
this.port = port;
String cmdUrl = "tcp://" + host + ":" + port;
connectRPC(cmdUrl); connectRPC(cmdUrl);
} }
public Client(int port, boolean debug) {
initClient(this.host, port, debug);
}
public Client(boolean debug) { public Client(boolean debug) {
initClient(this.host, this.port, debug);
}
private void initClient(String host, int port, boolean debug) {
try { try {
URL url = this.getClass().getResource("/win32-x86-64/wcf.exe"); URL url = this.getClass().getResource("/win32-x86-64/wcf.exe");
wcfPath = url.getFile(); wcfPath = url.getFile();
String[] cmd = new String[3]; String[] cmd = new String[4];
cmd[0] = wcfPath; cmd[0] = wcfPath;
cmd[1] = "start"; cmd[1] = "start";
cmd[2] = Integer.toString(port);
if (debug) { if (debug) {
cmd[2] = "debug"; cmd[3] = "debug";
} else { } else {
cmd[2] = ""; cmd[3] = "";
} }
int status = Runtime.getRuntime().exec(cmd).waitFor(); int status = Runtime.getRuntime().exec(cmd).waitFor();
if (status != 0) { if (status != 0) {
@ -49,6 +61,7 @@ public class Client {
System.exit(-1); System.exit(-1);
} }
isLocalHostPort = true; isLocalHostPort = true;
String cmdUrl = "tcp://" + host + ":" + port;
connectRPC(cmdUrl); connectRPC(cmdUrl);
} catch (Exception e) { } catch (Exception e) {
logger.error("初始化失败: {}", e); logger.error("初始化失败: {}", e);
@ -296,7 +309,7 @@ public class Client {
isReceivingMsg = true; isReceivingMsg = true;
msgQ = new ArrayBlockingQueue<WxMsg>(qSize); msgQ = new ArrayBlockingQueue<WxMsg>(qSize);
String msgUrl = cmdUrl.replace("10086", "10087"); String msgUrl = "tcp://" + this.host + ":" + (this.port + 1);
Thread thread = new Thread(new Runnable() { Thread thread = new Thread(new Runnable() {
public void run() { public void run() {
listenMsg(msgUrl); listenMsg(msgUrl);

View File

@ -8,18 +8,18 @@ public class Main {
public static void main(String[] args) { public static void main(String[] args) {
// 连接远程 RPC // 连接远程 RPC
// final String url = "tcp://192.168.1.104:10086"; // Client client = new Client("127.0.0.1", 10086);
// Client client = new Client(url);
// 本地启动 RPC // 本地启动 RPC
Client client = new Client(true); Client client = new Client(true); // 默认 10086 端口
// Client client = new Client(10088,true); // 也可以指定端口
// 是否已登录 // 是否已登录
logger.info("isLogin: {}", client.isLogin()); logger.info("isLogin: {}", client.isLogin());
/*
// 登录账号 wxid // 登录账号 wxid
logger.info("wxid: {}", client.getSelfWxid()); logger.info("wxid: {}", client.getSelfWxid());
/*
// 消息类型 // 消息类型
logger.info("message types: {}", client.getMsgTypes()); logger.info("message types: {}", client.getMsgTypes());