mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 18:20:43 +00:00
琚帶绔?- 淇 MTU 闂锛氬す MSS + 璺緞 MTU 鎺㈡祴锛堝叕缃戝彲鐢ㄧ巼 48% -> 100%锛?- 澶嶇敤 HTTP 杩炴帴锛堝厤鎺夋瘡娆℃柊寤?TLS 鐨?30% 鎻℃墜澶辫触锛?- 姣忓垎閽熷洖澶存壘灞€鍩熺綉锛岃嚜鍔ㄥ垏鍥炲揩 400 鍊嶇殑璺緞 - 鐢婚潰蹇冭烦甯э細闈欐鏃剁渷娴侀噺锛屽鎴风浠嶇煡閬撴祦鏄椿鐨?- 閿佸睆鏃剁粰鍑哄彲鎿嶄綔鐨勬彁绀? 鎵嬭〃绔?- 鍐呯疆 GTS Root R4 / GlobalSign Root CA锛屼慨 SSLHandshakeException - 杩炴帴閿欒缈昏瘧鎴愪汉璇濓紙璇佷功/鏃堕棿/瑙f瀽/瓒呮椂鍒嗗埆鎻愮ず锛?- 缁忎腑杞繛涓婂悗鐢ㄦ湇鍔″櫒鎶ョ殑鍦板潃鍒锋柊宸查厤瀵硅褰?- 鏂板灞€鍩熺綉杩炴帴椤甸潰銆佹湇鍔″櫒寤惰繜妫€娴? 鏈嶅姟鍣ㄧ - 鏀寔 chunked 璇锋眰浣擄紙淇瘡 16 绉掍竴娆$殑杩炴帴閿欎贡涓庡ぇ闈㈢Н 502锛?- 缃戠粶璋冧紭鑴氭湰 net-tune.sh锛堝紑鏈鸿嚜鍔ㄥ簲鐢級 - 绠$悊椤碉細鎵归噺鍒犻櫎銆佺綉缁滀綋妫€銆佷笅杞藉尯 - 闅ч亾鏀?HTTP/2 + 鍙岃繛鎺? 鏂囨。 - 璁稿彲鍗忚 / 瀹夎鍓嶅繀璇?/ 瀹夎鍚庨』鐭ワ紙浣滆€咃細灏忛害瀛愶級
148 lines
6.5 KiB
Java
148 lines
6.5 KiB
Java
import com.lanremote.watch.Json;
|
|
import com.lanremote.watch.RelayTransport;
|
|
import com.lanremote.watch.RemoteClient;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 手表端经中转服务器的联调测试。
|
|
*
|
|
* 这条链路才是真正要交付的:
|
|
*
|
|
* Java 手表 --HTTPS 长轮询--> 中转服务器 <--HTTPS-- Python 被控端
|
|
*
|
|
* 用法: java JavaRelayTest <中转地址> <配对码>
|
|
*/
|
|
public class JavaRelayTest {
|
|
|
|
private static int passed = 0;
|
|
private static int failed = 0;
|
|
|
|
private static void check(String name, boolean condition) {
|
|
check(name, condition, "");
|
|
}
|
|
|
|
private static void check(String name, boolean condition, String detail) {
|
|
if (condition) {
|
|
passed++;
|
|
System.out.println(" [PASS] " + name);
|
|
} else {
|
|
failed++;
|
|
System.out.println(" [FAIL] " + name + " " + detail);
|
|
}
|
|
}
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
String url = args.length > 0 ? args[0] : "http://127.0.0.1:8090";
|
|
String code = args.length > 1 ? args[1] : "135790";
|
|
System.out.println("中转地址: " + url + " 配对码: " + code);
|
|
System.out.println();
|
|
|
|
// ---------------- 1. 传输层自己 ----------------
|
|
System.out.println("一、RelayTransport 构造");
|
|
RelayTransport probe = new RelayTransport(url, code, "中转测试手表");
|
|
check("地址归一化去掉了末尾斜杠",
|
|
probe.getBaseUrl().equals(url.replaceAll("/+$", "")),
|
|
probe.getBaseUrl());
|
|
check("初始状态是未连接", !probe.isClosed());
|
|
|
|
// ---------------- 2. 经中转握手 ----------------
|
|
System.out.println();
|
|
System.out.println("二、经中转连被控端(握手)");
|
|
RemoteClient client = new RemoteClient();
|
|
client.setDevice("watch-relay-test", "中转测试手表");
|
|
Map<String, Object> reply =
|
|
client.connectViaRelay(url, code, null, new Silent(), 30000);
|
|
check("握手返回 ok", Json.bool(reply, "ok", false), String.valueOf(reply));
|
|
check("拿到设备令牌", Json.str(reply, "token", "").length() == 32,
|
|
Json.str(reply, "token", ""));
|
|
check("拿到被控端名字",
|
|
Json.str(reply, "serverName", "").length() > 0,
|
|
Json.str(reply, "serverName", ""));
|
|
check("客户端认为已连接", client.isConnected());
|
|
check("传输方式是中转", "中转".equals(client.transportName()),
|
|
client.transportName());
|
|
System.out.println(" 被控端: " + Json.str(reply, "serverName", "?"));
|
|
String token = Json.str(reply, "token", "");
|
|
|
|
// ---------------- 3. 命令往返 ----------------
|
|
System.out.println();
|
|
System.out.println("三、经中转发命令");
|
|
long started = System.currentTimeMillis();
|
|
Map<String, Object> pong = client.call(Json.obj("cmd", "info"), 30000);
|
|
long cost = System.currentTimeMillis() - started;
|
|
check("info 返回 ok", Json.bool(pong, "ok", false), String.valueOf(pong));
|
|
System.out.println(" 往返 " + cost + " ms");
|
|
|
|
Map<String, Object> features =
|
|
client.call(Json.obj("cmd", "feature_list"), 30000);
|
|
List<Object> items = Json.list(features, "features");
|
|
check("功能列表经中转拿到", Json.bool(features, "ok", false)
|
|
&& items.size() > 100, items.size() + " 个");
|
|
|
|
Map<String, Object> ran = client.call(Json.obj(
|
|
"cmd", "feature_run", "name", "world_clock",
|
|
"params", Json.obj()), 30000);
|
|
check("执行功能经中转成功", Json.bool(ran, "ok", false),
|
|
String.valueOf(ran));
|
|
check("功能有真实输出",
|
|
Json.str(ran, "note", "").contains("北京"),
|
|
Json.str(ran, "note", ""));
|
|
|
|
// ---------------- 4. 鉴权仍然生效 ----------------
|
|
System.out.println();
|
|
System.out.println("四、中转只是管道,鉴权仍由被控端做");
|
|
RemoteClient bad = new RemoteClient();
|
|
bad.setDevice("watch-bad", "坏手表");
|
|
Map<String, Object> refused = bad.connectViaRelay(
|
|
url, "000000", null, new Silent(), 30000);
|
|
check("错的配对码连不上", !Json.bool(refused, "ok", false),
|
|
String.valueOf(refused));
|
|
check("给出了原因", Json.str(refused, "error", "").length() > 0,
|
|
Json.str(refused, "error", ""));
|
|
System.out.println(" 原因: " + Json.str(refused, "error", "?"));
|
|
bad.close();
|
|
|
|
// ---------------- 5. 令牌免配对重连 ----------------
|
|
System.out.println();
|
|
System.out.println("五、用已保存的令牌重连(下次打开不用再输码)");
|
|
// 先断开第一条连接 —— 这才是实际用法(手表关了再打开)
|
|
client.close();
|
|
check("断开后 isConnected 为 false", !client.isConnected());
|
|
Thread.sleep(1500);
|
|
RemoteClient again = new RemoteClient();
|
|
again.setDevice("watch-relay-test", "中转测试手表");
|
|
Map<String, Object> authed =
|
|
again.connectViaRelay(url, code, token, new Silent(), 30000);
|
|
check("令牌登录成功", Json.bool(authed, "ok", false),
|
|
String.valueOf(authed));
|
|
check("新连接能发命令",
|
|
Json.bool(again.call(Json.obj("cmd", "ping"), 30000), "ok", false));
|
|
again.close();
|
|
|
|
// ---------------- 6. 断开干净 ----------------
|
|
System.out.println();
|
|
System.out.println("六、断开处理");
|
|
client.close();
|
|
check("关闭后 isConnected 为 false", !client.isConnected());
|
|
|
|
System.out.println();
|
|
System.out.println("======================================================");
|
|
System.out.println("通过 " + passed + " 项,失败 " + failed + " 项");
|
|
System.exit(failed == 0 ? 0 : 1);
|
|
}
|
|
|
|
/** 事件回调:这个测试不关心事件。 */
|
|
static class Silent implements RemoteClient.Listener {
|
|
@Override
|
|
public void onEvent(String event, Map<String, Object> message) {
|
|
}
|
|
|
|
@Override
|
|
public void onDisconnected(String reason) {
|
|
System.out.println(" (断开: " + reason + ")");
|
|
}
|
|
}
|
|
}
|