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


Java WebSocketAdapter類代碼示例

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


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

示例1: connect

import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的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

示例2: testClose

import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void testClose() throws Throwable {
  websocketAction(new Action<ServerWebSocket>() {
    @Override
    public void on(ServerWebSocket ws) {
      ws.close();
    }
  });
  client.connect(new WebSocketAdapter() {
    @Override
    public void onWebSocketClose(int statusCode, String reason) {
      resume();
    }
  }, URI.create(uri()));
  await();
}
 
開發者ID:cettia,項目名稱:asity,代碼行數:17,代碼來源:ServerWebSocketTestBase.java

示例3: testSendTextFrame

import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void testSendTextFrame() throws Throwable {
  websocketAction(new Action<ServerWebSocket>() {
    @Override
    public void on(ServerWebSocket ws) {
      ws.send("A Will Remains in the Ashes");
    }
  });
  client.connect(new WebSocketAdapter() {
    @Override
    public void onWebSocketText(String message) {
      threadAssertEquals(message, "A Will Remains in the Ashes");
      resume();
    }
  }, URI.create(uri()));
  await();
}
 
開發者ID:cettia,項目名稱:asity,代碼行數:18,代碼來源:ServerWebSocketTestBase.java

示例4: testSendBinaryFrame

import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void testSendBinaryFrame() throws Throwable {
  websocketAction(new Action<ServerWebSocket>() {
    @Override
    public void on(ServerWebSocket ws) {
      ws.send(ByteBuffer.wrap(new byte[]{0x00, 0x01, 0x02}).asReadOnlyBuffer());
    }
  });
  client.connect(new WebSocketAdapter() {
    @Override
    public void onWebSocketBinary(byte[] payload, int offset, int len) {
      threadAssertTrue(Arrays.equals(payload, new byte[]{0x00, 0x01, 0x02}));
      resume();
    }
  }, URI.create(uri()));
  await();
}
 
開發者ID:cettia,項目名稱:asity,代碼行數:18,代碼來源:ServerWebSocketTestBase.java

示例5: testOntext

import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void testOntext() throws Throwable {
  websocketAction(new Action<ServerWebSocket>() {
    @Override
    public void on(ServerWebSocket ws) {
      ws.ontext(new Action<String>() {
        @Override
        public void on(String data) {
          threadAssertEquals(data, "A road of winds the water builds");
          resume();
        }
      });
    }
  });
  client.connect(new WebSocketAdapter() {
    @Override
    public void onWebSocketConnect(Session session) {
      session.getRemote().sendString("A road of winds the water builds", ASYNC);
    }
  }, URI.create(uri()));
  await();
}
 
開發者ID:cettia,項目名稱:asity,代碼行數:23,代碼來源:ServerWebSocketTestBase.java

示例6: testOnbinary

import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void testOnbinary() throws Throwable {
  websocketAction(new Action<ServerWebSocket>() {
    @Override
    public void on(ServerWebSocket ws) {
      ws.onbinary(new Action<ByteBuffer>() {
        @Override
        public void on(ByteBuffer data) {
          threadAssertEquals(data, ByteBuffer.wrap(new byte[]{0x00, 0x01, 0x02}));
          resume();
        }
      });
    }
  });
  client.connect(new WebSocketAdapter() {
    @Override
    public void onWebSocketConnect(Session session) {
      session.getRemote().sendBytes(ByteBuffer.wrap(new byte[]{0x00, 0x01, 0x02}), ASYNC);
    }
  }, URI.create(uri()));
  await();
}
 
開發者ID:cettia,項目名稱:asity,代碼行數:23,代碼來源:ServerWebSocketTestBase.java

示例7: testOncloseByClient

import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void testOncloseByClient() throws Throwable {
  websocketAction(new Action<ServerWebSocket>() {
    @Override
    public void on(ServerWebSocket ws) {
      ws.onclose(new VoidAction() {
        @Override
        public void on() {
          resume();
        }
      });
    }
  });
  client.connect(new WebSocketAdapter() {
    @Override
    public void onWebSocketConnect(Session session) {
      session.close();
    }
  }, URI.create(uri()));
  await();
}
 
開發者ID:cettia,項目名稱:asity,代碼行數:22,代碼來源:ServerWebSocketTestBase.java

示例8: close

import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void close() {
    performer.clientListener(new WebSocketAdapter() {
        @Override
        public void onWebSocketClose(int statusCode, String reason) {
            performer.start();
        }
    })
    .onserver(new Action<ServerWebSocket>() {
        @Override
        public void on(ServerWebSocket ws) {
            ws.close();
        }
    })
    .connect();
}
 
開發者ID:vibe-project,項目名稱:vibe-java-platform,代碼行數:17,代碼來源:ServerWebSocketTest.java

示例9: close_idempotent

import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void close_idempotent() {
    performer.clientListener(new WebSocketAdapter() {
        @Override
        public void onWebSocketClose(int statusCode, String reason) {
            performer.start();
        }
    })
    .onserver(new Action<ServerWebSocket>() {
        @Override
        public void on(ServerWebSocket ws) {
            ws.close();
            ws.close();
        }
    })
    .connect();
}
 
開發者ID:vibe-project,項目名稱:vibe-java-platform,代碼行數:18,代碼來源:ServerWebSocketTest.java

示例10: send_text

import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void send_text() {
    performer.clientListener(new WebSocketAdapter() {
        @Override
        public void onWebSocketText(String message) {
            assertThat(message, is("A Will Remains in the Ashes"));
            performer.start();
        }
    })
    .onserver(new Action<ServerWebSocket>() {
        @Override
        public void on(ServerWebSocket ws) {
            ws.send("A Will Remains in the Ashes");
        }
    })
    .connect();
}
 
開發者ID:vibe-project,項目名稱:vibe-java-platform,代碼行數:18,代碼來源:ServerWebSocketTest.java

示例11: send_binary

import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void send_binary() {
    performer.clientListener(new WebSocketAdapter() {
        @Override
        public void onWebSocketBinary(byte[] payload, int offset, int len) {
            assertThat(payload, is(new byte[] { 0x00, 0x01, 0x02 }));
            performer.start();
        }
    })
    .onserver(new Action<ServerWebSocket>() {
        @Override
        public void on(ServerWebSocket ws) {
            ws.send(ByteBuffer.wrap(new byte[] { 0x00, 0x01, 0x02 }).asReadOnlyBuffer());
        }
    })
    .connect();
}
 
開發者ID:vibe-project,項目名稱:vibe-java-platform,代碼行數:18,代碼來源:ServerWebSocketTest.java

示例12: onclose_by_client

import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void onclose_by_client() {
    performer.clientListener(new WebSocketAdapter() {
        @Override
        public void onWebSocketConnect(Session sess) {
            sess.close();
        }
    })
    .onserver(new Action<ServerWebSocket>() {
        @Override
        public void on(ServerWebSocket ws) {
            ws.onclose(new VoidAction() {
                @Override
                public void on() {
                    performer.start();
                }
            });
        }
    })
    .connect();
}
 
開發者ID:vibe-project,項目名稱:vibe-java-platform,代碼行數:22,代碼來源:ServerWebSocketTest.java

示例13: onMessage

import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Override
public void onMessage(WebSocketAdapter client, String message) {
    try {
        onMessage((HarAdapter) client, (JSONObject) JSONValue.parse(message));
    } catch (Exception ex) {
        LOG.log(Level.SEVERE, ex.getMessage(), ex);
    }
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:9,代碼來源:HarCompareHandler.java

示例14: unwrap

import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void unwrap() throws Throwable {
  websocketAction(new Action<ServerWebSocket>() {
    @Override
    public void on(ServerWebSocket ws) {
      threadAssertTrue(ws.unwrap(ChannelHandlerContext.class) instanceof ChannelHandlerContext);
      threadAssertTrue(ws.unwrap(WebSocketServerHandshaker.class) instanceof
        WebSocketServerHandshaker);
      threadAssertTrue(ws.unwrap(FullHttpRequest.class) instanceof FullHttpRequest);
      resume();
    }
  });
  client.connect(new WebSocketAdapter(), URI.create(uri()));
  await();
}
 
開發者ID:cettia,項目名稱:asity,代碼行數:16,代碼來源:NettyServerWebSocketTest.java

示例15: unwrap

import org.eclipse.jetty.websocket.api.WebSocketAdapter; //導入依賴的package包/類
@Test
public void unwrap() throws Throwable {
  websocketAction(new Action<ServerWebSocket>() {
    @Override
    public void on(ServerWebSocket ws) {
      threadAssertTrue(ws.unwrap(org.vertx.java.core.http.ServerWebSocket.class) instanceof org
        .vertx.java.core.http.ServerWebSocket);
      resume();
    }
  });
  client.connect(new WebSocketAdapter(), URI.create(uri()));
  await();
}
 
開發者ID:cettia,項目名稱:asity,代碼行數:14,代碼來源:VertxServerWebSocketTest.java


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