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


Java WebSocket类代码示例

本文整理汇总了Java中io.socket.engineio.client.transports.WebSocket的典型用法代码示例。如果您正苦于以下问题:Java WebSocket类的具体用法?Java WebSocket怎么用?Java WebSocket使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WebSocket类属于io.socket.engineio.client.transports包,在下文中一共展示了WebSocket类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: open

import io.socket.engineio.client.transports.WebSocket; //导入依赖的package包/类
/**
 * Connects the client.
 *
 * @return a reference to to this object.
 */
public Socket open() {
    EventThread.exec(new Runnable() {
        @Override
        public void run() {
            String transportName;
            if (Socket.this.rememberUpgrade && Socket.priorWebsocketSuccess && Socket.this.transports.contains(WebSocket.NAME)) {
                transportName = WebSocket.NAME;
            } else if (0 == Socket.this.transports.size()) {
                // Emit error on next tick so it can be listened to
                final Socket self = Socket.this;
                EventThread.nextTick(new Runnable() {
                    @Override
                    public void run() {
                        self.emit(Socket.EVENT_ERROR, new EngineIOException("No transports available"));
                    }
                });
                return;
            } else {
                transportName = Socket.this.transports.get(0);
            }
            Socket.this.readyState = ReadyState.OPENING;
            Transport transport = Socket.this.createTransport(transportName);
            Socket.this.setTransport(transport);
            transport.open();
        }
    });
    return this;
}
 
开发者ID:socketio,项目名称:engine.io-client-java,代码行数:34,代码来源:Socket.java

示例2: filterUpgrades

import io.socket.engineio.client.transports.WebSocket; //导入依赖的package包/类
@Test
public void filterUpgrades() {
    Socket.Options opts = new Socket.Options();
    opts.transports = new String[] {Polling.NAME};
    Socket socket = new Socket(opts);
    List<String> upgrades = new ArrayList<String>() {{
        add(Polling.NAME);
        add(WebSocket.NAME);
    }};
    List<String> expected = new ArrayList<String>() {{add(Polling.NAME);}};
    assertThat(socket.filterUpgrades(upgrades), is(expected));
}
 
开发者ID:socketio,项目名称:engine.io-client-java,代码行数:13,代码来源:SocketTest.java

示例3: rememberWebsocket

import io.socket.engineio.client.transports.WebSocket; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void rememberWebsocket() throws InterruptedException {
    final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();

    EventThread.exec(new Runnable() {
        @Override
        public void run() {
            final Socket socket = new Socket(createOptions());

            socket.on(Socket.EVENT_UPGRADE, new Emitter.Listener() {
                @Override
                public void call(Object... args) {
                    Transport transport = (Transport) args[0];
                    socket.close();
                    if (WebSocket.NAME.equals(transport.name)) {
                        Socket.Options opts = new Socket.Options();
                        opts.port = PORT;
                        opts.rememberUpgrade = true;

                        Socket socket2 = new Socket(opts);
                        socket2.open();
                        values.offer(socket2.transport.name);
                        socket2.close();
                    }
                }
            });
            socket.open();
            values.offer(socket.transport.name);
        }
    });

    assertThat((String)values.take(), is(Polling.NAME));
    assertThat((String)values.take(), is(WebSocket.NAME));
}
 
开发者ID:socketio,项目名称:engine.io-client-java,代码行数:35,代码来源:ServerConnectionTest.java

示例4: notRememberWebsocket

import io.socket.engineio.client.transports.WebSocket; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void notRememberWebsocket() throws InterruptedException {
    final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();

    EventThread.exec(new Runnable() {
        @Override
        public void run() {
            final Socket socket = new Socket(createOptions());

            socket.on(Socket.EVENT_UPGRADE, new Emitter.Listener() {
                @Override
                public void call(Object... args) {
                    Transport transport = (Transport)args[0];
                    socket.close();
                    if (WebSocket.NAME.equals(transport.name)) {
                        Socket.Options opts = new Socket.Options();
                        opts.port = PORT;
                        opts.rememberUpgrade = false;

                        final Socket socket2 = new Socket(opts);
                        socket2.open();
                        values.offer(socket2.transport.name);
                        socket2.close();
                    }
                }
            });
            socket.open();
            values.offer(socket.transport.name);
        }
    });

    assertThat((String) values.take(), is(Polling.NAME));
    assertThat((String)values.take(), is(not(WebSocket.NAME)));
}
 
开发者ID:socketio,项目名称:engine.io-client-java,代码行数:35,代码来源:ServerConnectionTest.java

示例5: Socket

import io.socket.engineio.client.transports.WebSocket; //导入依赖的package包/类
public Socket(Options opts) {
    if (opts.host != null) {
        String hostname = opts.host;
        boolean ipv6 = hostname.split(":").length > 2;
        if (ipv6) {
            int start = hostname.indexOf('[');
            if (start != -1) hostname = hostname.substring(start + 1);
            int end = hostname.lastIndexOf(']');
            if (end != -1) hostname = hostname.substring(0, end);
        }
        opts.hostname = hostname;
    }

    this.secure = opts.secure;

    if (opts.port == -1) {
        // if no port is specified manually, use the protocol default
        opts.port = this.secure ? 443 : 80;
    }

    this.hostname = opts.hostname != null ? opts.hostname : "localhost";
    this.port = opts.port;
    this.query = opts.query != null ?
            ParseQS.decode(opts.query) : new HashMap<String, String>();
    this.upgrade = opts.upgrade;
    this.path = (opts.path != null ? opts.path : "/engine.io").replaceAll("/$", "") + "/";
    this.timestampParam = opts.timestampParam != null ? opts.timestampParam : "t";
    this.timestampRequests = opts.timestampRequests;
    this.transports = new ArrayList<String>(Arrays.asList(opts.transports != null ?
            opts.transports : new String[]{Polling.NAME, WebSocket.NAME}));
    this.transportOptions = opts.transportOptions != null ?
            opts.transportOptions : new HashMap<String, Transport.Options>();
    this.policyPort = opts.policyPort != 0 ? opts.policyPort : 843;
    this.rememberUpgrade = opts.rememberUpgrade;
    this.callFactory = opts.callFactory != null ? opts.callFactory : defaultCallFactory;
    this.webSocketFactory = opts.webSocketFactory != null ? opts.webSocketFactory : defaultWebSocketFactory;
    if (callFactory == null) {
        if (defaultOkHttpClient == null) {
            defaultOkHttpClient = new OkHttpClient();
        }
        callFactory = defaultOkHttpClient;
    }
    if (webSocketFactory == null) {
        if (defaultOkHttpClient == null) {
            defaultOkHttpClient = new OkHttpClient();
        }
        webSocketFactory = defaultOkHttpClient;
    }
}
 
开发者ID:socketio,项目名称:engine.io-client-java,代码行数:50,代码来源:Socket.java

示例6: setDefaultOkHttpWebSocketFactory

import io.socket.engineio.client.transports.WebSocket; //导入依赖的package包/类
public static void setDefaultOkHttpWebSocketFactory(okhttp3.WebSocket.Factory factory) {
    defaultWebSocketFactory = factory;
}
 
开发者ID:socketio,项目名称:engine.io-client-java,代码行数:4,代码来源:Socket.java


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