当前位置: 首页>>代码示例>>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;未经允许,请勿转载。