本文整理匯總了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);
}
}
示例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();
}
示例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();
}
}
示例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();
}
}
}
示例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();
}
}
示例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();
}
}
}
示例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();
}
示例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());
}
示例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);
}
}
示例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());
}
示例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 );
}
}
示例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);
}
}
示例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;
}
}
}
示例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);
}
}