当前位置: 首页>>代码示例>>Java>>正文


Java Connection类代码示例

本文整理汇总了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);
        }
    }
}
 
开发者ID:AdrianBZG,项目名称:PhoneChat,代码行数:24,代码来源:SendingTask.java

示例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);
        }
    }
}
 
开发者ID:AdrianBZG,项目名称:PhoneChat,代码行数:25,代码来源:DisconnectionTask.java

示例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");
    }
}
 
开发者ID:itead,项目名称:IoTgo_Android_App,代码行数:21,代码来源:SendingTask.java

示例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");
    }
}
 
开发者ID:itead,项目名称:IoTgo_Android_App,代码行数:20,代码来源:DisconnectionTask.java

示例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) {
        }
    }
}
 
开发者ID:AdrianBZG,项目名称:PhoneChat,代码行数:18,代码来源:ConnectionTask.java

示例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()));

}
 
开发者ID:apache,项目名称:guacamole-client,代码行数:15,代码来源:GuacamoleWebSocketTunnelServlet.java

示例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) {
    }
}
 
开发者ID:itead,项目名称:IoTgo_Android_App,代码行数:14,代码来源:WebSocket.java

示例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));
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:36,代码来源:WebSocketServiceTest.java

示例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;
}
 
开发者ID:videonext,项目名称:ECF-WebSocket,代码行数:17,代码来源:WebSocketClient.java

示例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));
}
 
开发者ID:knowledgecode,项目名称:WebSocket-for-Android,代码行数:16,代码来源:WebSocket.java

示例11: onOpen

import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
public void onOpen(Connection connection) {
	this.connection = connection;
}
 
开发者ID:ismb,项目名称:jemma.osgi.dal.web-apis,代码行数:4,代码来源:DALEventWebSocket.java

示例12: onOpen

import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
public void onOpen(Connection connection) {
	this.connection=connection;
}
 
开发者ID:ismb,项目名称:it.ismb.pert.osgi.dal.web-apis,代码行数:4,代码来源:DALEventWebSocket.java

示例13: MainFrame

import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
public MainFrame(int id, Connection creator) {
	super(id, creator);
	this.sendElement();
}
 
开发者ID:magik6k,项目名称:JWWF,代码行数:5,代码来源:MainFrame.java

示例14: Widget

import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
protected Widget(int id, Connection connection) {
	this.id = id;
	this.connection = connection;
}
 
开发者ID:magik6k,项目名称:JWWF,代码行数:5,代码来源:Widget.java

示例15: WebSocketOutputStream

import org.eclipse.jetty.websocket.WebSocket.Connection; //导入依赖的package包/类
public WebSocketOutputStream(Connection connection) {
	super(65536);
	this.connection = connection;
}
 
开发者ID:videonext,项目名称:ECF-WebSocket,代码行数:5,代码来源:WebSocketOutputStream.java


注:本文中的org.eclipse.jetty.websocket.WebSocket.Connection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。