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


Java WebSocketClient.connect方法代码示例

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


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

示例1: connect

import org.eclipse.jetty.websocket.client.WebSocketClient; //导入方法依赖的package包/类
@Test
public void connect() throws Exception {
   final WebSocketClient client = new WebSocketClient();

   client.start();

   final WebSocketAdapter socket = new WebSocketAdapter() {
      @Override
      public void onWebSocketConnect(Session session) {
         session.getRemote().sendStringByFuture("yo man!");

         session.close();
      }
   };

   client.connect(
      socket,
      URI.create("ws://localhost:8080/ws/"),
      new ClientUpgradeRequest()
   );

   Thread.sleep(1000L);

   client.stop();
}
 
开发者ID:arielr52,项目名称:sqlsocket,代码行数:26,代码来源:WebSocketTester.java

示例2: main

import org.eclipse.jetty.websocket.client.WebSocketClient; //导入方法依赖的package包/类
public static void main(String[] args) {
    String destUri = "ws://192.168.100.78:2014";
    if (args.length > 0) {
        destUri = args[0];
    }
    WebSocketClient client = new WebSocketClient();
    SimpleEchoSocket socket = new SimpleEchoSocket();
    try {
        client.start();
        URI echoUri = new URI(destUri);
        ClientUpgradeRequest request = new ClientUpgradeRequest();
        client.connect(socket, echoUri, request);
        System.out.printf("Connecting to : %s%n", echoUri);
        socket.awaitClose(5, TimeUnit.SECONDS);
    } catch (Throwable t) {
        t.printStackTrace();
    } finally {
        try {
            client.stop();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:East196,项目名称:maker,代码行数:25,代码来源:SimpleEchoClient.java

示例3: connect

import org.eclipse.jetty.websocket.client.WebSocketClient; //导入方法依赖的package包/类
/**
 * Connects to the Rosbridge host at the provided URI.
 * @param rosBridgeURI the URI to the ROS Bridge websocket server. Note that ROS Bridge by default uses port 9090. An example URI is: ws://localhost:9090
 * @param waitForConnection if true, then this method will block until the connection is established. If false, then return immediately.
 */
public void connect(String rosBridgeURI, boolean waitForConnection){
	WebSocketClient client = new WebSocketClient();
	try {
		client.start();
		URI echoUri = new URI(rosBridgeURI);
		ClientUpgradeRequest request = new ClientUpgradeRequest();
		client.connect(this, echoUri, request);
		System.out.printf("Connecting to : %s%n", echoUri);
		if(waitForConnection){
			this.waitForConnection();
		}

	} catch (Throwable t) {
		t.printStackTrace();
	}

}
 
开发者ID:h2r,项目名称:java_rosbridge,代码行数:23,代码来源:RosBridge.java

示例4: main

import org.eclipse.jetty.websocket.client.WebSocketClient; //导入方法依赖的package包/类
public static void main(String[] args) {
	String destUri = "ws://echo.websocket.org";
	if (args.length > 0) {
		destUri = args[0];
	}
	WebSocketClient client = new WebSocketClient();
	SimpleEchoSocket socket = new SimpleEchoSocket();
	try {
		client.start();
		URI echoUri = new URI(destUri);
		ClientUpgradeRequest request = new ClientUpgradeRequest();
		client.connect(socket, echoUri, request);
		System.out.printf("Connecting to : %s%n", echoUri);
		socket.awaitClose(15, TimeUnit.SECONDS);
	} catch (Throwable t) {
		t.printStackTrace();
	} finally {
		try {
			client.stop();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:h2r,项目名称:java_rosbridge,代码行数:25,代码来源:SimpleEchoClient.java

示例5: start

import org.eclipse.jetty.websocket.client.WebSocketClient; //导入方法依赖的package包/类
@Override
public boolean start() throws IOException {
  String destUri = "wss://ws-feed.exchange.coinbase.com";
  WebSocketClient client = new WebSocketClient(new SslContextFactory());
  try {
    LOG.info("connecting to coinbsae feed");
    client.start();
    URI echoUri = new URI(destUri);
    ClientUpgradeRequest request = new ClientUpgradeRequest();
    client.connect(this, echoUri, request);
    LOG.info("done connecting");
  } catch (Throwable t) {
    t.printStackTrace();
  }
  return advance();
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-bigtable-examples,代码行数:17,代码来源:CoinbaseSocket.java

示例6: notifyWebSockets

import org.eclipse.jetty.websocket.client.WebSocketClient; //导入方法依赖的package包/类
private void notifyWebSockets(final String data) {
    URI uri = URI.create("ws://localhost:8080/trades/");

    WebSocketClient client = new WebSocketClient();
    try {
        try {
            client.start();
            // The socket that receives events
            TradeSocket socket = new TradeSocket();
            // Attempt Connect
            Future<Session> fut = client.connect(socket, uri);
            // Wait for Connect
            Session session = fut.get();
            // Send a message
            session.getRemote().sendString(data);
            // Close session
            session.close();
        } finally {
            client.stop();
        }
    } catch (Throwable t) {
        //t.printStackTrace(System.err);
    }
}
 
开发者ID:rozza,项目名称:reactiveBTC,代码行数:25,代码来源:TailTrades.java

示例7: connect

import org.eclipse.jetty.websocket.client.WebSocketClient; //导入方法依赖的package包/类
public void connect(User user, String url) {
if (socket == null) {
	String destUri = "ws://" + url;
	client = new WebSocketClient();
	
	client.getPolicy().setMaxTextMessageSize(1000000);
	socket = new ClientWebSocket(user);
	try {
		client.start();
		URI echoUri = new URI(destUri);
		ClientUpgradeRequest request = new ClientUpgradeRequest();
		client.connect(socket, echoUri, request);
		LOGGER.info("Connecting to : %s%n", echoUri);
		
	} catch (Throwable t) {
		t.printStackTrace();
		client = null;
	}
}
  }
 
开发者ID:lyrgard,项目名称:HexScape,代码行数:21,代码来源:ClientNetwork.java

示例8: LOLOLOL

import org.eclipse.jetty.websocket.client.WebSocketClient; //导入方法依赖的package包/类
public void LOLOLOL(){
 System.out.println( "Hello World!" );
    String dest = "ws://localhost:8080/jsr356toUpper";
            WebSocketClient client = new WebSocketClient();
            try {
                 
                ToUpperClientSocket socket = new ToUpperClientSocket();
                client.start();
                URI echoUri = new URI(dest);
                ClientUpgradeRequest request = new ClientUpgradeRequest();
                client.connect(socket, echoUri, request);
                socket.getLatch().await();
                ByteBuffer buf = ByteBuffer.allocate(5);
                buf.put(0, (byte)254);
                buf.order(ByteOrder.LITTLE_ENDIAN);
                buf.putInt(1, 5);
                socket.sendMessage(buf);
                Thread.sleep(10000l);
                String name = "BadPlayer";
                ByteBuffer buf1 = ByteBuffer.allocate(1 + 2*name.length());
                buf1.put(0, (byte)0);
                for (int i=0;i<name.length();i++) {
                	buf1.order(ByteOrder.LITTLE_ENDIAN);
                    buf.putShort(1 + i*2 ,(short)name.charAt(i));
                }
     
            } catch (Throwable t) {
                t.printStackTrace();
            } finally {
                try {
                    client.stop();
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }

}
 
开发者ID:BadPlayer555,项目名称:MeMezBots-Dev,代码行数:39,代码来源:OK.java

示例9: connect

import org.eclipse.jetty.websocket.client.WebSocketClient; //导入方法依赖的package包/类
/**
 * Connect the websocket.
 * Attempts to connect to the websocket on a remote Miniserver.
 *
 * @return
 *         true if connection request initiated correctly, false if not
 */
boolean connect() {
    logger.trace("[{}] connect() websocket", debugId);
    if (state != ClientState.IDLE) {
        close("Attempt to connect a websocket in non-idle state: " + state);
        return false;
    }

    synchronized (state) {
        socket = new LxWebSocket();
        wsClient = new WebSocketClient();

        try {
            wsClient.start();

            URI target = new URI("ws://" + host.getHostAddress() + ":" + port + SOCKET_URL);
            ClientUpgradeRequest request = new ClientUpgradeRequest();
            request.setSubProtocols("remotecontrol");

            wsClient.connect(socket, target, request);
            setClientState(ClientState.CONNECTING);
            startResponseTimeout();

            logger.debug("[{}] Connecting to server : {} ", debugId, target);
            return true;

        } catch (Exception e) {
            setClientState(ClientState.IDLE);
            close("Connection to websocket failed : " + e.getMessage());
            return false;
        }
    }
}
 
开发者ID:ppieczul,项目名称:org.openhab.binding.loxone,代码行数:40,代码来源:LxWsClient.java

示例10: connect

import org.eclipse.jetty.websocket.client.WebSocketClient; //导入方法依赖的package包/类
public void connect() throws Exception {
    ClientUpgradeRequest request = new ClientUpgradeRequest();
    request.setHeader("Cookie", "CurseAuthToken=" + URLEncoder.encode(getAuthToken()));
    WebSocketClient client = new WebSocketClient(new SslContextFactory());
    TwitchNotificationSocket socket = new TwitchNotificationSocket(this);
    client.start();
    URI destUri = new URI("wss://notifications-eu-v1.curseapp.net/");
    System.out.println("Connecting to " + destUri);
    client.connect(socket, destUri, request);
}
 
开发者ID:renepreuss,项目名称:TwitchMessenger,代码行数:11,代码来源:TwitchMessenger.java

示例11: socketTest

import org.eclipse.jetty.websocket.client.WebSocketClient; //导入方法依赖的package包/类
public void socketTest() throws Exception {
    final String topic = "my-property/use/my-ns/my-topic1";
    final String consumerUri = "ws://localhost:" + port + "/ws/consumer/persistent/" + topic + "/my-sub";
    final String producerUri = "ws://localhost:" + port + "/ws/producer/persistent/" + topic;
    URI consumeUri = URI.create(consumerUri);
    URI produceUri = URI.create(producerUri);

    consumeClient = new WebSocketClient();
    SimpleConsumerSocket consumeSocket = new SimpleConsumerSocket();
    produceClient = new WebSocketClient();
    SimpleProducerSocket produceSocket = new SimpleProducerSocket();

    consumeClient.start();
    ClientUpgradeRequest consumeRequest = new ClientUpgradeRequest();
    Future<Session> consumerFuture = consumeClient.connect(consumeSocket, consumeUri, consumeRequest);
    log.info("Connecting to : {}", consumeUri);

    ClientUpgradeRequest produceRequest = new ClientUpgradeRequest();
    produceClient.start();
    Future<Session> producerFuture = produceClient.connect(produceSocket, produceUri, produceRequest);
    Assert.assertTrue(consumerFuture.get().isOpen());
    Assert.assertTrue(producerFuture.get().isOpen());

    consumeSocket.awaitClose(1, TimeUnit.SECONDS);
    produceSocket.awaitClose(1, TimeUnit.SECONDS);
    Assert.assertTrue(produceSocket.getBuffer().size() > 0);
    Assert.assertEquals(produceSocket.getBuffer(), consumeSocket.getBuffer());
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:29,代码来源:ProxyAuthenticationTest.java

示例12: run

import org.eclipse.jetty.websocket.client.WebSocketClient; //导入方法依赖的package包/类
@Override
public void run(CommandLine theCommandLine) throws ParseException, Exception {
	String target = theCommandLine.getOptionValue("t");
	if (isBlank(target) || (!target.startsWith("ws://") && !target.startsWith("wss://"))) {
		throw new ParseException("Target (-t) needs to be in the form \"ws://foo\" or \"wss://foo\"");
	}
	
	IdDt subsId = new IdDt(theCommandLine.getOptionValue("i"));
	
	WebSocketClient client = new WebSocketClient();
	SimpleEchoSocket socket = new SimpleEchoSocket(subsId.getIdPart());
	try {
		client.start();
		URI echoUri = new URI(target);
		ClientUpgradeRequest request = new ClientUpgradeRequest();
		ourLog.info("Connecting to : {}", echoUri);
		client.connect(socket, echoUri, request);

		while (!myQuit) {
			Thread.sleep(500L);
		}

		ourLog.info("Shutting down websocket client");
	} finally {
		try {
			client.stop();
		} catch (Exception e) {
			ourLog.error("Failure", e);
		}
	}
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:32,代码来源:WebsocketSubscribeCommand.java

示例13: openSession

import org.eclipse.jetty.websocket.client.WebSocketClient; //导入方法依赖的package包/类
private <T> Tuple<T> openSession(T socket) {
    WebSocketClient client = new WebSocketClient();
    try {
        client.start();
        client.connect(socket, uri);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return new Tuple<>(client, socket);
}
 
开发者ID:mslosarz,项目名称:nextrtc-signaling-server,代码行数:11,代码来源:PerformanceTest.java

示例14: checkClientConnection

import org.eclipse.jetty.websocket.client.WebSocketClient; //导入方法依赖的package包/类
@Test
public void checkClientConnection() throws Exception {
	
       URI uri = URI.create("ws://localhost:8080/event/?path=c%3A/Work/results/Test.txt");

       WebSocketClient client = new WebSocketClient();
       client.start();
       try {
           
       	Session connection = null;
       	try {
           	final EventClientSocket clientSocket = new EventClientSocket();
                // Attempt Connect
               Future<Session> fut = client.connect(clientSocket, uri);
              
               // Wait for Connect
               connection = fut.get();
               
               // Send a message
               connection.getRemote().sendString("Hello World");
               
               // Close session from the server
               while(connection.isOpen()) {
               	Thread.sleep(100);
               }
           } finally {
               if (connection!=null) connection.close();
           }
       } catch (Throwable t) {
           t.printStackTrace(System.err);
           throw t;
       } finally {
       	client.stop();
       }
   }
 
开发者ID:eclipse,项目名称:dawnsci,代码行数:36,代码来源:EventClientTest.java

示例15: connect

import org.eclipse.jetty.websocket.client.WebSocketClient; //导入方法依赖的package包/类
public static void connect(WebSocketClient client, URI uri){
    run++;
    try{
        try{
            //Start client

            client.start();
            // The socket that receives events

            MyWebSocketHandler socket = new MyWebSocketHandler();
            // Attempt Connect

            Future<Session> fut = client.connect(socket, uri);
            // Wait for Connect
            Session session = fut.get();

            //Save session and uri into te handler so that it can try to reconnect
            socket.setClientUri(client,uri);

            // Send a test msg
            //session.getRemote().sendString("MSG|videosws|Saludos|Que onda hugo");


            // Close session
            //session.close();


        }catch (Exception e) {
            System.out.println(e);
            Thread.sleep(15000);
            connect(client, uri);


        }
    }
    catch (Throwable t)
    {
        t.printStackTrace(System.err);
    }

}
 
开发者ID:kevuno,项目名称:Offline-Streamer,代码行数:42,代码来源:WebSocketTest.java


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