类 OkHttpWebSocketTransport
java.lang.Object
io.agentscope.core.model.transport.websocket.OkHttpWebSocketTransport
- 所有已实现的接口:
WebSocketTransport
WebSocket client implementation based on OkHttp.
Features:
- Mature and stable HTTP client library
- Built-in ping/pong heartbeat (pingInterval)
- Better connection pool management
- Client instance is reusable
Usage example:
WebSocketTransport client = OkHttpWebSocketTransport.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 OkHttpWebSocketTransportcreate()Create a client with default configuration.static OkHttpWebSocketTransportcreate(WebSocketTransportConfig config) Create a client with custom configuration.static OkHttpWebSocketTransportcreate(okhttp3.OkHttpClient client) Create a client with custom OkHttpClient.voidshutdown()Shutdown the client and release resources.
-
方法详细资料
-
create
Create a client with default configuration.- 返回:
- OkHttpWebSocketTransport instance
-
create
Create a client with custom OkHttpClient.- 参数:
client- Custom OkHttpClient instance- 返回:
- OkHttpWebSocketTransport instance
-
create
Create a client with custom configuration.This method supports proxy configuration and other advanced settings.
- 参数:
config- the WebSocket client configuration- 返回:
- OkHttpWebSocketTransport 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
-