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


Java WebSocketClient類代碼示例

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


WebSocketClient類屬於org.eclipse.jetty.websocket.client包,在下文中一共展示了WebSocketClient類的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: triggerReload

import org.eclipse.jetty.websocket.client.WebSocketClient; //導入依賴的package包/類
@Test
public void triggerReload() throws Exception {
	WebSocketClient client = new WebSocketClient();
	try {
		Socket socket = openSocket(client, new Socket());
		this.server.triggerReload();
		Thread.sleep(500);
		this.server.stop();
		assertThat(socket.getMessages(0))
				.contains("http://livereload.com/protocols/official-7");
		assertThat(socket.getMessages(1)).contains("command\":\"reload\"");
	}
	finally {
		client.stop();
	}
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:17,代碼來源:LiveReloadServerTests.java

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

示例4: triggerReload

import org.eclipse.jetty.websocket.client.WebSocketClient; //導入依賴的package包/類
@Test
public void triggerReload() throws Exception {
	WebSocketClient client = new WebSocketClient();
	try {
		Socket socket = openSocket(client, new Socket());
		this.server.triggerReload();
		Thread.sleep(500);
		this.server.stop();
		assertThat(socket.getMessages(0),
				containsString("http://livereload.com/protocols/official-7"));
		assertThat(socket.getMessages(1), containsString("command\":\"reload\""));
	}
	finally {
		client.stop();
	}
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:17,代碼來源:LiveReloadServerTests.java

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

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

import org.eclipse.jetty.websocket.client.WebSocketClient; //導入依賴的package包/類
/**
 * Establishes a connection with the webtrends stream api
 * @see akka.actor.UntypedActor#preStart()
 */
public void preStart() throws Exception {
			
	// initialize the uuid generator which is based on time and ethernet address
	this.uuidGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
	
	// authenticate with the webtrends service
	WebtrendsTokenRequest tokenRequest = new WebtrendsTokenRequest(this.authUrl, this.authAudience, this.authScope, this.clientId, this.clientSecret);
	this.oAuthToken = tokenRequest.execute();		
	
	// initialize the webtrends stream socket client and connect the listener
	this.webtrendsStreamSocketClient = new WebSocketClient();
	try {
		this.webtrendsStreamSocketClient.start();
		ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
		this.webtrendsStreamSocketClient.connect(this, new URI(this.eventStreamUrl), upgradeRequest);
		await(5, TimeUnit.SECONDS);
	} catch(Exception e) {
		throw new RuntimeException("Unable to connect to web socket: " + e.getMessage(), e);
	}
	
	this.componentRegistryRef.tell(new ComponentRegistrationMessage(EVENT_SOURCE_ID, ComponentType.STREAM_LISTENER, getSelf()), getSelf());
}
 
開發者ID:mnxfst,項目名稱:stream-analyzer,代碼行數:27,代碼來源:WebtrendsStreamListenerActor.java

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

示例11: createFileListener

import org.eclipse.jetty.websocket.client.WebSocketClient; //導入依賴的package包/類
private void createFileListener() throws Exception {
	
       URI uri = URI.create(urlBuilder.getEventURL());

       this.client = new WebSocketClient(exec);
       client.start();
      
       final DataEventSocket clientSocket = new DataEventSocket();
       // Attempt Connect
       Future<Session> fut = client.connect(clientSocket, uri);

       // Wait for Connect
       connection = fut.get();

       // Send a message
       connection.getRemote().sendString("Connected to "+urlBuilder.getPath());
}
 
開發者ID:eclipse,項目名稱:dawnsci,代碼行數:18,代碼來源:RemoteDataset.java

示例12: openConnection

import org.eclipse.jetty.websocket.client.WebSocketClient; //導入依賴的package包/類
@Override
public void openConnection() throws IOException {

	this.logger.info( getId() + " is opening a connection to the DM." );
	try {
		this.client = new WebSocketClient();
		this.socket = new AgentWebSocket( this.messageQueue );
		this.client.start();

		URI dmUri = new URI( "ws://" + this.dmIp + ":" + this.dmPort + HttpConstants.DM_SOCKET_PATH );
		this.logger.fine( "Connecting to " + dmUri );
		ClientUpgradeRequest request = new ClientUpgradeRequest();

		Future<Session> fut = this.client.connect( this.socket, dmUri, request );
		this.clientSession = fut.get();

	} catch( Exception e ) {
		throw new IOException( e );
	}
}
 
開發者ID:roboconf,項目名稱:roboconf-platform,代碼行數:21,代碼來源:HttpAgentClient.java

示例13: preStart

import org.eclipse.jetty.websocket.client.WebSocketClient; //導入依賴的package包/類
/**
 * Establishes a connection with the webtrends stream api
 * @see akka.actor.UntypedActor#preStart()
 */
public void preStart() throws Exception {
	
	// authenticate with the webtrends service
	WebtrendsTokenRequest tokenRequest = new WebtrendsTokenRequest(this.authUrl, this.authAudience, this.authScope, this.clientId, this.clientSecret);
	this.oAuthToken = tokenRequest.execute();		
	
	// initialize the webtrends stream socket client and connect the listener
	this.webtrendsStreamSocketClient = new WebSocketClient();
	try {
		this.webtrendsStreamSocketClient.start();
		ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
		this.webtrendsStreamSocketClient.connect(this, new URI(this.eventStreamUrl), upgradeRequest);
		await(5, TimeUnit.SECONDS);
	} catch(Exception e) {
		throw new RuntimeException("Unable to connect to web socket: " + e.getMessage(), e);
	}		
}
 
開發者ID:mnxfst,項目名稱:webtrends-kafka-producer,代碼行數:22,代碼來源:WebtrendsStreamListenerActor.java

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

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


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