本文整理汇总了Java中org.eclipse.jetty.websocket.WebSocket.Connection类的典型用法代码示例。如果您正苦于以下问题:Java Connection类的具体用法?Java Connection怎么用?Java Connection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Connection类属于org.eclipse.jetty.websocket.WebSocket包,在下文中一共展示了Connection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
@Override
public void execute(String rawArgs, CallbackContext ctx) {
try {
String args = new JSONArray(rawArgs).getString(0);
Connection conn = _map.get(Integer.parseInt(args.substring(0, 8), 16));
if (conn != null) {
if (args.charAt(8) == '1') {
byte[] binary = Base64.decode(args.substring(args.indexOf(',') + 1), Base64.NO_WRAP);
conn.sendMessage(binary, 0, binary.length);
} else {
conn.sendMessage(args.substring(9));
}
} else {
}
} catch (Exception e) {
if (!ctx.isFinished()) {
PluginResult result = new PluginResult(Status.ERROR);
result.setKeepCallback(true);
ctx.sendPluginResult(result);
}
}
}
示例2: execute
import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
@Override
public void execute(String rawArgs, CallbackContext ctx) {
try {
JSONArray args = new JSONArray(rawArgs);
int id = Integer.parseInt(args.getString(0), 16);
int code = args.getInt(1);
String reason = args.getString(2);
Connection conn = _map.get(id);
if (conn != null) {
if (code > 0) {
conn.close(code, reason);
} else {
conn.close();
}
}
} catch (Exception e) {
if (!ctx.isFinished()) {
PluginResult result = new PluginResult(Status.ERROR);
result.setKeepCallback(true);
ctx.sendPluginResult(result);
}
}
}
示例3: execute
import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
@Override
public void execute(JSONArray args, CallbackContext ctx) {
try {
int id = args.getInt(0);
String data = args.getString(1);
boolean binaryString = args.getBoolean(2);
Connection conn = _map.get(id);
if (conn != null) {
if (binaryString) {
byte[] binary = Base64.decode(data, Base64.NO_WRAP);
conn.sendMessage(binary, 0, binary.length);
} else {
conn.sendMessage(data);
}
}
} catch (Exception e) {
ctx.error("send");
}
}
示例4: execute
import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
@Override
public void execute(JSONArray args, CallbackContext ctx) {
try {
int id = args.getInt(0);
int code = args.getInt(1);
String reason = args.getString(2);
Connection conn = _map.get(id);
if (conn != null) {
if (code > 0) {
conn.close(code, reason);
} else {
conn.close();
}
}
} catch (Exception e) {
ctx.error("close");
}
}
示例5: ConnectionTask
import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
/**
* Constructor
*
* @param factory
* @param map
*/
public ConnectionTask(WebSocketClientFactory factory, SparseArray<Connection> map) {
_factory = factory;
_map = map;
if (!_factory.isRunning()) {
try {
_factory.start();
} catch (Exception e) {
}
}
}
示例6: closeConnection
import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
/**
* Sends the given status on the given WebSocket connection and closes the
* connection.
*
* @param connection The WebSocket connection to close.
* @param guac_status The status to send.
*/
public static void closeConnection(Connection connection,
GuacamoleStatus guac_status) {
connection.close(guac_status.getWebSocketCode(),
Integer.toString(guac_status.getGuacamoleStatusCode()));
}
示例7: initialize
import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
_factory = new WebSocketClientFactory();
_conn = new SparseArray<Connection>();
_create = new ConnectionTask(_factory, _conn);
_send = new SendingTask(_conn);
_close = new DisconnectionTask(_conn);
try {
start();
} catch (Exception e) {
}
}
示例8: testCloseChannel
import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
@Test
public void testCloseChannel() throws Exception {
//given
final Config config = Application.getInstance(Config.class);
final WebSocketService webSocketService = Application.getInstance(WebSocketService.class);
webSocketService.removeChannels("/websocket");
final WebSocketClientFactory factory = new WebSocketClientFactory();
factory.start();
final String url = "ws://" + config.getConnectorHttpHost() + ":" + config.getConnectorHttpPort() + "/websocket";
//when
final WebSocketClient client = new WebSocketClient(factory);
client.open(new URI(url), new WebSocket.OnTextMessage() {
@Override
public void onOpen(Connection connection) {
// intentionally left blank
}
@Override
public void onClose(int closeCode, String message) {
// intentionally left blank
}
@Override
public void onMessage(String data) {
// intentionally left blank
}
}).get(5, TimeUnit.SECONDS);
webSocketService.close("/websocket");
//then
assertThat(webSocketService.getChannels("/websocket"), not(nullValue()));
assertThat(webSocketService.getChannels("/websocket").size(), equalTo(0));
}
示例9: createConnectSocket
import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
/**
* @since 4.4
*/
protected WebSocket createConnectSocket(URI remote, int timeout) throws ECFException {
// Get socket factory and create/connect socket
WebSocket websocket = new WebSocket();
org.eclipse.jetty.websocket.WebSocketClient client = factory.newWebSocketClient();
try {
Connection conn = client.open(remote, websocket).get(timeout, TimeUnit.MILLISECONDS);
websocket.onOpen(conn);
} catch (Exception e) {
throw new ECFException("Could not create socket to connect to id=" + remote + " ( " + e.getMessage() + ")"); //$NON-NLS-1$
}
return websocket;
}
示例10: initialize
import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
@Override
public void initialize(CordovaInterface cordova, final CordovaWebView webView) {
super.initialize(cordova, webView);
_factory = new WebSocketClientFactory();
_conn = new SparseArray<Connection>();
_executor = Executors.newSingleThreadExecutor();
_runner = new TaskRunner();
_runner.setTask(CREATE_TASK, new ConnectionTask(_factory, _conn));
_runner.setTask(SEND_TASK, new SendingTask(_conn));
_runner.setTask(CLOSE_TASK, new DisconnectionTask(_conn));
_runner.setTask(RESET_TASK, new ResetTask(_conn));
_runner.setTask(DESTROY_TASK, new DestroyTask(_factory, _conn));
_executor.execute(_runner);
Log.setLogLevel(getLogLevel(this.preferences));
}
示例11: onOpen
import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
public void onOpen(Connection connection) {
this.connection = connection;
}
示例12: onOpen
import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
public void onOpen(Connection connection) {
this.connection=connection;
}
示例13: MainFrame
import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
public MainFrame(int id, Connection creator) {
super(id, creator);
this.sendElement();
}
示例14: Widget
import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
protected Widget(int id, Connection connection) {
this.id = id;
this.connection = connection;
}
示例15: WebSocketOutputStream
import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
public WebSocketOutputStream(Connection connection) {
super(65536);
this.connection = connection;
}