【发布时间】:2015-09-15 21:19:13
【问题描述】:
我正在使用 javax.websocket 类连接到 Java 中的 websocket 服务器。
import javax.websocket.DeploymentException;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
import java.io.IOException;
import java.net.URI;
public class WSClient {
private WebSocketContainer webSocketContainer;
public void sendMessage(URI endpointURI, String message) throws IOException, DeploymentException {
Session session = webSocketContainer.connectToServer(MyClientEndpoint.class, endpointURI);
session.getAsyncRemote().sendText(message);
}
}
对于初始 HTTP 握手,我想在客户端
上向请求中添加额外的 HTTP 标头这可能吗?
我知道这可以在服务器端使用ServerEndpointConfig.Configurator.modifyHandshake。客户端有类似的解决方案吗?
【问题讨论】:
标签: java websocket java-websocket