本文整理汇总了Java中org.eclipse.jetty.websocket.WebSocket.Connection方法的典型用法代码示例。如果您正苦于以下问题:Java WebSocket.Connection方法的具体用法?Java WebSocket.Connection怎么用?Java WebSocket.Connection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.websocket.WebSocket
的用法示例。
在下文中一共展示了WebSocket.Connection方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toWebSocketConnection
import org.eclipse.jetty.websocket.WebSocket; //导入方法依赖的package包/类
WebSocketConnection toWebSocketConnection(final WebSocket.Connection connection) {
return new WebSocketConnection() {
@Override
public void write(String data) throws IOException {
connection.sendMessage(data);
}
@Override
public void disconnect() {
connection.disconnect();
}
@Override
public boolean isOpen() {
return connection.isOpen();
}
@Override
public void setMaxIdleTime(int ms) {
connection.setMaxIdleTime(ms);
}
};
}
示例2: simpleTest
import org.eclipse.jetty.websocket.WebSocket; //导入方法依赖的package包/类
@Test
public void simpleTest() throws Exception
{
final int port = 6666;
String connectionURI = "ws://localhost:" + port + WebSocketServerInputOperator.DEFAULT_EXTENSION;
final String message = "hello world";
WebSocketServerInputOperator wssio = new TestWSSIO();
wssio.setPort(port);
wssio.setup(null);
WebSocketClientFactory clientFactory = new WebSocketClientFactory();
clientFactory.start();
WebSocketClient client = new WebSocketClient(clientFactory);
Future<WebSocket.Connection> connectionFuture = client.open(new URI(connectionURI), new TestWebSocket());
WebSocket.Connection connection = connectionFuture.get(5, TimeUnit.SECONDS);
connection.sendMessage(message);
long startTime = System.currentTimeMillis();
while (startTime + 10000 > System.currentTimeMillis()) {
if (TestWSSIO.messages.size() >= 1) {
break;
}
Thread.sleep(100);
}
Assert.assertEquals("The number of messages recieved is incorrect.", 1, TestWSSIO.messages.size());
Assert.assertEquals("Incorrect message received", message, TestWSSIO.messages.get(0));
connection.close();
wssio.teardown();
}
示例3: testEnded
import org.eclipse.jetty.websocket.WebSocket; //导入方法依赖的package包/类
@Override
public void testEnded(String host) {
try {
for(WebSocket.Connection connection : samplerConnections) {
connection.close();
}
webSocketClientFactory.stop();
} catch (Exception e) {
log.error("sampler error when close.", e);
}
}
示例4: getConnection
import org.eclipse.jetty.websocket.WebSocket; //导入方法依赖的package包/类
public WebSocket.Connection getConnection() {
return this.connection;
}
示例5: getConnection
import org.eclipse.jetty.websocket.WebSocket; //导入方法依赖的package包/类
public WebSocket.Connection getConnection() {
return conn;
}
示例6: connectWebsocket
import org.eclipse.jetty.websocket.WebSocket; //导入方法依赖的package包/类
public void connectWebsocket(String url, int sampleEveryN, boolean showMessages) {
try {
int timeout = 9000; // 9 seconds
System.out.println("NOTE: For GeoEvent Stream Service append /subscribe to the Web Socket URL");
System.out.println("Starting: If you see rapid connection lost messages. Ctrl-C and check you're URL");
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setTrustAll(true);
sslContextFactory.start();
final WebSocketClientFactory factory = new WebSocketClientFactory();
factory.start();
WebSocketClient client = factory.newWebSocketClient();
URI uri = new URI(url);
//WebSocketMessage msg = new WebSocketMessage();
//WebSocket.Connection websocketConnection = client.open(uri, new WebSocketMessage(sampleEveryN, showMessages)).get(5, TimeUnit.SECONDS);
WebSocket.Connection websocketConnection = client.open(uri, new WebSocketMessage(sampleEveryN, showMessages),timeout, TimeUnit.SECONDS);
//System.out.println(System.currentTimeMillis());
websocketConnection.setMaxTextMessageSize(MAX_MESSAGE_SIZE);
//System.out.println(timeout);
websocketConnection.setMaxIdleTime(timeout);
//websocketConnection.setMaxIdleTime(-1);
while (true) {
if (websocketConnection.isOpen()) {
// Wait a second
Thread.sleep(1000);
} else {
// Reopen
websocketConnection = client.open(uri, new WebSocketMessage(sampleEveryN, showMessages)).get(5, TimeUnit.SECONDS);
websocketConnection.setMaxTextMessageSize(MAX_MESSAGE_SIZE);
websocketConnection.setMaxIdleTime(timeout);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}