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