當前位置: 首頁>>代碼示例>>Java>>正文


Java WebSocketClient.start方法代碼示例

本文整理匯總了Java中org.eclipse.jetty.websocket.client.WebSocketClient.start方法的典型用法代碼示例。如果您正苦於以下問題:Java WebSocketClient.start方法的具體用法?Java WebSocketClient.start怎麽用?Java WebSocketClient.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jetty.websocket.client.WebSocketClient的用法示例。


在下文中一共展示了WebSocketClient.start方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: JsonWebSocketProtocolHandler

import org.eclipse.jetty.websocket.client.WebSocketClient; //導入方法依賴的package包/類
public JsonWebSocketProtocolHandler(NativeDeviceFactoryInterface deviceFactory) {
	super(deviceFactory);

	serialiser = GSON::toJson;
	deserialiser = GSON::fromJson;
	
	webSocketClient = new WebSocketClient();
	try {
		webSocketClient.start();

		URI uri = new URI("ws://localhost:8080/diozero");
		Logger.debug("Connecting to: {}...", uri);
		session = webSocketClient.connect(this, uri, new ClientUpgradeRequest()).get();
		Logger.debug("Connected to: {}", uri);
	} catch (Exception e) {
		throw new RuntimeIOException(e);
	}
}
 
開發者ID:mattjlewis,項目名稱:diozero,代碼行數:19,代碼來源:JsonWebSocketProtocolHandler.java

示例2: 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

示例3: 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

示例4: 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

示例5: create

import org.eclipse.jetty.websocket.client.WebSocketClient; //導入方法依賴的package包/類
@Override
public <T> T create(Class<T> interfaceClass, URL url, String userId,
		String password) {
	final WebSocketClient client = new WebSocketClient();
	clients.add(client);
	try {
		client.start();
		int i = url.getProtocol().equals("http") ? 7 : 8;
		URI uri = new URI("ws://" + url.toString().substring(i));
		Listener listener = new Listener();
		Session session = client.connect(listener, uri).get();
		return interfaceClass.cast(Proxy.newProxyInstance(
				Thread.currentThread().getContextClassLoader(),
				new Class<?>[] { interfaceClass, RequestAttributes.class,
						ResponseAttributes.class, ArrayElementsNotifier.class },
				new WebSocketJsonRpcHandler(session, listener)
				));
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:nict-wisdom,項目名稱:rasc,代碼行數:22,代碼來源:WebSocketJsonRpcClientFactory.java

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: main

import org.eclipse.jetty.websocket.client.WebSocketClient; //導入方法依賴的package包/類
public static void main(final String[] args) throws Exception {
	AppUtil.startLogging(args, 1);
	final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger("org.eclipse.jetty");
	if (!(logger instanceof ch.qos.logback.classic.Logger)) {
		return;
	}
	ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) logger;
	logbackLogger.setLevel(ch.qos.logback.classic.Level.INFO);

	final int serverPort = (args.length > 0) ? Integer.parseInt(args[0]) : DEFAULT_SERVER_PORT;
	final String destUri = "ws://localhost:" + Integer.toString(serverPort) + "/test";

	final SocketTestServer socketServer = new SocketTestServer();
	final SessionHandler sessionHandler = new SimpleSessionHandler(socketServer, new ServletSessionStore());
	final RequestHandler handler = new RequestHandler(null, sessionHandler);
	final Server server = new Server(serverPort);
	final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
	context.setContextPath("/");
	server.setHandler(context);
	context.addServlet(new ServletHolder(new EmbeddedServlet(handler)), "/*");

	server.start();
	System.out.println("Server started");

	Thread.sleep(10000);

	// Start Client
	final WebSocketClient client = new WebSocketClient();
	final SocketTestClient socket = new SocketTestClient();

	client.start();
	final URI uri = new URI(destUri);
	final ClientUpgradeRequest request = new ClientUpgradeRequest();
	System.out.printf("Connecting to : %s%n", uri);

	// wait for closed socket connection.
	socket.awaitClose(5,TimeUnit.SECONDS);
	client.stop();
}
 
開發者ID:emily-e,項目名稱:webframework,代碼行數:40,代碼來源:WebSocketsTest.java

示例14: 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

示例15: openSocket

import org.eclipse.jetty.websocket.client.WebSocketClient; //導入方法依賴的package包/類
private <T> T openSocket(WebSocketClient client, T socket) throws Exception,
		URISyntaxException, InterruptedException, ExecutionException, IOException {
	client.start();
	ClientUpgradeRequest request = new ClientUpgradeRequest();
	URI uri = new URI("ws://localhost:" + this.port + "/livereload");
	Session session = client.connect(socket, uri, request).get();
	session.getRemote().sendString(HANDSHAKE);
	Thread.sleep(200);
	return socket;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:11,代碼來源:LiveReloadServerTests.java


注:本文中的org.eclipse.jetty.websocket.client.WebSocketClient.start方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。