Skip to content

Commit

Permalink
chore[comment]: webSocket handshake instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Jan 19, 2024
1 parent f9e4b44 commit 9bfa8e1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void startClient() throws Exception {
var client = new JsonWebsocketClient(HostAndPort.valueOf("127.0.0.1:9000"), webSocketClientProtocolConfig);
var session = client.start();

// Websocket在建立tcp连接过后不能立刻通讯,还需要使用Http协议去握手升级成Websocket协议
// Websocket在建立tcp连接过后不能立刻通讯,还需要使用Http协议去握手升级成Websocket协议,这里等待一秒让websocket内部协议初始化完毕
// WebSocket握手是在客户端和服务器之间建立WebSocket连接的过程。它是通过HTTP/HTTPS协议完成的,后续将升级为WebSocket协议。
ThreadUtils.sleep(1000);

Expand All @@ -58,7 +58,6 @@ public void startClient() throws Exception {
for (int i = 0; i < 1000; i++) {
NetContext.getRouter().send(session, request);

ThreadUtils.sleep(1000);
var response = NetContext.getRouter().syncAsk(session, request, JsonHelloResponse.class, null).packet();
logger.info("sync json client receive [packet:{}] from server", JsonUtils.object2String(response));

Expand All @@ -69,6 +68,7 @@ public void accept(JsonHelloResponse jsonHelloResponse) {
logger.info("async json client receive [packet:{}] from server", JsonUtils.object2String(jsonHelloResponse));
}
});
ThreadUtils.sleep(1000);
}

ThreadUtils.sleep(Long.MAX_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void startClient() throws Exception {
var client = new WebsocketClient(HostAndPort.valueOf("127.0.0.1:9000"), webSocketClientProtocolConfig);
var session = client.start();

// Websocket在建立tcp连接过后不能立刻通讯,还需要使用Http协议去握手升级成Websocket协议
// Websocket在建立tcp连接过后不能立刻通讯,还需要使用Http协议去握手升级成Websocket协议,这里等待一秒让websocket内部协议初始化完毕
// WebSocket握手是在客户端和服务器之间建立WebSocket连接的过程。它是通过HTTP/HTTPS协议完成的,后续将升级为WebSocket协议。
ThreadUtils.sleep(1000);

Expand All @@ -58,7 +58,6 @@ public void startClient() throws Exception {
for (int i = 0; i < 1000; i++) {
NetContext.getRouter().send(session, request);

ThreadUtils.sleep(1000);
var response = NetContext.getRouter().syncAsk(session, request, WebsocketHelloResponse.class, null).packet();
logger.info("sync client receive [packet:{}] from server", JsonUtils.object2String(response));

Expand All @@ -69,6 +68,7 @@ public void accept(WebsocketHelloResponse jsonHelloResponse) {
logger.info("async client receive [packet:{}] from server", JsonUtils.object2String(jsonHelloResponse));
}
});
ThreadUtils.sleep(1000);
}

ThreadUtils.sleep(Long.MAX_VALUE);
Expand Down

0 comments on commit 9bfa8e1

Please sign in to comment.