类 JdkWebSocketTransport
java.lang.Object
io.agentscope.core.model.transport.websocket.JdkWebSocketTransport
- 所有已实现的接口:
WebSocketTransport
WebSocket client implementation based on JDK 11+ HttpClient.
Features:
- No additional dependencies, uses JDK built-in API
- Client instance is reusable
- Thread-safe
Usage example:
WebSocketTransport client = JdkWebSocketTransport.create();
WebSocketRequest request = WebSocketRequest.builder("wss://api.example.com/ws")
.header("Authorization", "Bearer token")
.build();
client.connect(request, String.class)
.flatMapMany(conn -> {
conn.send("{\"type\":\"config\"}").subscribe();
return conn.receive();
})
.subscribe(data -> handle(data));
-
方法概要
修饰符和类型方法说明<T> reactor.core.publisher.Mono<WebSocketConnection<T>> connect(WebSocketRequest request, Class<T> messageType) Establish a WebSocket connection.static JdkWebSocketTransportcreate()Create a client with default configuration.static JdkWebSocketTransportcreate(WebSocketTransportConfig config) Create a client with custom configuration.static JdkWebSocketTransportcreate(HttpClient httpClient) Create a client with custom HttpClient.voidshutdown()Shutdown the client and release resources.
-
方法详细资料
-
create
Create a client with default configuration.- 返回:
- JdkWebSocketTransport instance
-
create
Create a client with custom HttpClient.- 参数:
httpClient- Custom HttpClient instance- 返回:
- JdkWebSocketTransport instance
-
create
Create a client with custom configuration.This method supports proxy configuration and other advanced settings.
- 参数:
config- the WebSocket client configuration- 返回:
- JdkWebSocketTransport instance
-
connect
public <T> reactor.core.publisher.Mono<WebSocketConnection<T>> connect(WebSocketRequest request, Class<T> messageType) 从接口复制的说明:WebSocketTransportEstablish a WebSocket connection.- 指定者:
connect在接口中WebSocketTransport- 类型参数:
T- Message type: String for text protocol, byte[] for binary protocol- 参数:
request- Connection request configurationmessageType- Class object for message type (String.class or byte[].class)- 返回:
- Mono that emits WebSocketConnection on successful connection
-
shutdown
public void shutdown()从接口复制的说明:WebSocketTransportShutdown the client and release resources.After shutdown, this client should not be used anymore.
- 指定者:
shutdown在接口中WebSocketTransport
-