当前位置: 首页>>代码示例>>Java>>正文


Java WebSocket.Connection方法代码示例

本文整理汇总了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);
        }
    };
}
 
开发者ID:alibaba,项目名称:jvm-sandbox,代码行数:24,代码来源:WebSocketAcceptorServlet.java

示例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();
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:37,代码来源:WebSocketServerInputOperatorTest.java

示例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);
    }
}
 
开发者ID:kawasima,项目名称:jmeter-websocket,代码行数:12,代码来源:WebSocketSampler.java

示例4: getConnection

import org.eclipse.jetty.websocket.WebSocket; //导入方法依赖的package包/类
public WebSocket.Connection getConnection() {
    return this.connection;
}
 
开发者ID:signalfx,项目名称:signalfx-java,代码行数:4,代码来源:WebSocketTransport.java

示例5: getConnection

import org.eclipse.jetty.websocket.WebSocket; //导入方法依赖的package包/类
public WebSocket.Connection getConnection() {
	return conn;
}
 
开发者ID:reflexworks,项目名称:reflexservlet,代码行数:4,代码来源:ReflexWebSocketBase.java

示例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();
    }
}
 
开发者ID:david618,项目名称:Simulator,代码行数:53,代码来源:WebSocketSink.java


注:本文中的org.eclipse.jetty.websocket.WebSocket.Connection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。