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


Java WebSocketClient类代码示例

本文整理汇总了Java中org.eclipse.jetty.websocket.WebSocketClient的典型用法代码示例。如果您正苦于以下问题:Java WebSocketClient类的具体用法?Java WebSocketClient怎么用?Java WebSocketClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


WebSocketClient类属于org.eclipse.jetty.websocket包,在下文中一共展示了WebSocketClient类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runVC

import org.eclipse.jetty.websocket.WebSocketClient; //导入依赖的package包/类
public static VirtualClient runVC(final String[] args) throws Exception {
    final int game = args.length > 0 ? Integer.parseInt(args[0]) : 1;
    final String host = "localhost";
    //final String host = "192.168.0.1";
    final int port = 8282;
    final WebSocketClientFactory factory = new WebSocketClientFactory();
    factory.setBufferSize(4096);
    factory.start();
    final WebSocketClient client = factory.newWebSocketClient();
    client.setMaxIdleTime(60 * 1000 * 5);
    client.setMaxTextMessageSize(1024 * 64);
    final VirtualClient virtualClient = new VirtualClient("virtual-client", client, host, port, "io");
    virtualClient.start();
    final IMessage message1 = MESSAGES.newClient(virtualClient.getName());
    virtualClient.send(message1);
    final IMessage message2 = MESSAGES.newGameConnection(game);
    virtualClient.send(message2);
    //virtualClient.stop();
    //factory.stop();
    return virtualClient;
}
 
开发者ID:arie-benichou,项目名称:blockplus,代码行数:22,代码来源:BlockplusServer.java

示例2: simpleTest

import org.eclipse.jetty.websocket.WebSocketClient; //导入依赖的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: testCloseChannel

import org.eclipse.jetty.websocket.WebSocketClient; //导入依赖的package包/类
@Test
public void testCloseChannel() throws Exception {
    //given
    final Config config = Application.getInstance(Config.class);
    final WebSocketService webSocketService = Application.getInstance(WebSocketService.class);
    webSocketService.removeChannels("/websocket");
    final WebSocketClientFactory factory = new WebSocketClientFactory();
    factory.start();
    final String url = "ws://" + config.getConnectorHttpHost() + ":" + config.getConnectorHttpPort() + "/websocket";

    //when
    final WebSocketClient client = new WebSocketClient(factory);
    client.open(new URI(url), new WebSocket.OnTextMessage() {
        @Override
        public void onOpen(Connection connection) {
            // intentionally left blank
        }

        @Override
        public void onClose(int closeCode, String message) {
            // intentionally left blank
        }

        @Override
        public void onMessage(String data) {
            // intentionally left blank
        }
    }).get(5, TimeUnit.SECONDS);

    webSocketService.close("/websocket");

    //then
    assertThat(webSocketService.getChannels("/websocket"), not(nullValue()));
    assertThat(webSocketService.getChannels("/websocket").size(), equalTo(0));
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:36,代码来源:WebSocketServiceTest.java

示例4: connect

import org.eclipse.jetty.websocket.WebSocketClient; //导入依赖的package包/类
protected void connect(URI uri, long timeout, JettyConnection connection) throws Exception{	
	if(!fact.isStarted())
		fact.start();
		
	WebSocketClient ws = fact.newWebSocketClient();
	ws.setProtocol(getProtocolName());
	
	if(timeout > 0)
		ws.open(uri, connection, timeout, TimeUnit.MILLISECONDS);
	else
		ws.open(uri,connection);
}
 
开发者ID:greenaddress,项目名称:WalletCordova,代码行数:13,代码来源:WampJettyFactory.java

示例5: createWebSocketClient

import org.eclipse.jetty.websocket.WebSocketClient; //导入依赖的package包/类
/**
 * A factory method for {@link WebSocketClient} class
 * 
 * @return
 */
protected WebSocketClient createWebSocketClient() {
	factory = new WebSocketClientFactory();
	factory.getSslContextFactory().setTrustAll(false);
	try {
		factory.start();
	} catch (Exception e) {
		throw new IllegalStateException(e);
	}
	final WebSocketClient client = factory.newWebSocketClient();
	// you can manipulate the client by overriding this method.
	return client;
}
 
开发者ID:inventit,项目名称:mqtt-websocket-jdk16-android,代码行数:18,代码来源:WebSocketNetworkModule.java

示例6: getClient

import org.eclipse.jetty.websocket.WebSocketClient; //导入依赖的package包/类
public WebSocketClient getClient() {
    return this.client;
}
 
开发者ID:arie-benichou,项目名称:blockplus,代码行数:4,代码来源:VirtualClient.java

示例7: VirtualClient

import org.eclipse.jetty.websocket.WebSocketClient; //导入依赖的package包/类
public VirtualClient(final String username, final WebSocketClient client, final String host, final int port, final String base) {
    this.name = username;
    this.client = client;
    this.uri = "ws://" + host + ":" + port + "/" + base;
}
 
开发者ID:arie-benichou,项目名称:blockplus,代码行数:6,代码来源:VirtualClient.java

示例8: JsonRpcWsClient

import org.eclipse.jetty.websocket.WebSocketClient; //导入依赖的package包/类
public JsonRpcWsClient(URI serviceUri, String protocol, WebSocketClient client, ObjectMapper mapper) {
    super(mapper, false);
    mServiceUri = serviceUri;
    mServiceProtocol = protocol;
    mClient = client;
}
 
开发者ID:promovicz,项目名称:better-jsonrpc,代码行数:7,代码来源:JsonRpcWsClient.java

示例9: getWebSocketClient

import org.eclipse.jetty.websocket.WebSocketClient; //导入依赖的package包/类
public WebSocketClient getWebSocketClient() {
    return mClient;
}
 
开发者ID:promovicz,项目名称:better-jsonrpc,代码行数:4,代码来源:JsonRpcWsClient.java

示例10: connectWebsocket

import org.eclipse.jetty.websocket.WebSocketClient; //导入依赖的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.WebSocketClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。