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


Java IO类代码示例

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


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

示例1: connect

import io.socket.client.IO; //导入依赖的package包/类
public boolean connect() {
    boolean result = false;
    if (socket == null) {
        try {
            socket = IO.socket(config.getServer());
            socket.on(config.getTopic(), onNewMessage);
            socket.connect();
            result = true;
        } catch (URISyntaxException e) {
            socket = null;
            Log.e(TAG, "Not possible to connect to SocketIO server", e);
        }
    } else {
        throw new IllegalArgumentException("Connect - Socket is not null.");
    }

    return result;
}
 
开发者ID:videgro,项目名称:Ships,代码行数:19,代码来源:SocketIoClient.java

示例2: start

import io.socket.client.IO; //导入依赖的package包/类
@Override
public void start() {
  if (socketToken == null) {
    return;
  }

  if (socket == null) {
    try {
      socket = IO.socket(SOCKET_URI, getIOOptions());
      socket.on("event", new StreamLabsEventListener(eventBus));
    } catch (URISyntaxException e) {
      logger.error("Failed connection to Stream Labs socket.io", e);
    }
  } else {
    stop();
  }

  socket.connect();
}
 
开发者ID:Juraji,项目名称:Biliomi,代码行数:20,代码来源:StreamLabsSocketSession.java

示例3: initNetworking

import io.socket.client.IO; //导入依赖的package包/类
GenericOutcome initNetworking() {
    if (!networkInitialized) {
        String url = "http://" + HOSTNAME + ":" + PORT;
        String queryString = PID_KEY + "=" + getProcessID() + "&" +
                            SDK_VERSION_KEY + "=" + GameLiftServerAPI.SDK_VERSION + "&" +
                            FLAVOR_KEY + "=" + FLAVOR;

        IO.Options options = new IO.Options();
        options.query = queryString;
        options.reconnection = false;
        options.transports = new String[] { "websocket" };

        try {
            Socket socket = IO.socket(url, options);
            sender = new AuxProxyMessageSender(socket);
            network = new Network(socket, this);
            GenericOutcome result = network.connect();
            networkInitialized = result.isSuccessful();
            return result;
        } catch (URISyntaxException e) {
            return new GenericOutcome(new GameLiftError(GameLiftErrorType.LOCAL_CONNECTION_FAILED, e));
        }
    }

    return new GenericOutcome();
}
 
开发者ID:BoxtrotStudio,项目名称:amazon-gamelift-serversdk-java,代码行数:27,代码来源:ServerState.java

示例4: connectToServer

import io.socket.client.IO; //导入依赖的package包/类
private void connectToServer(final String nickname) {
    try {
        socket = IO.socket("http://localhost:5000");
        socket.connect();
        socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {

            @Override
            public void call(Object... args) {
                System.out.println("Connected: "+socket.id());
                socket.emit("login", nickname);
            }
        });
        socket.connect();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:nerlihmax,项目名称:YetAnotherMMORPG,代码行数:18,代码来源:Game.java

示例5: connect

import io.socket.client.IO; //导入依赖的package包/类
@Override
public void connect() {

    try {
        socket  = IO.socket(Constants.SOCKET_URL);
        socket.on(Socket.EVENT_CONNECT, args -> {
            connectionWithBackend = true;
            connectionRelay.call(true);
        })
                .on(COMMAND_MESSAGE, args -> {
                    messageRelay.call(gson.fromJson((String) args[0], CommandMessage.class));
                })
                .on(Socket.EVENT_DISCONNECT, args -> {
                    connectionRelay.call(false);
                    connectionWithBackend = false;
                });
        socket.connect();


    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

}
 
开发者ID:elloza,项目名称:ArduinoBLEAndroid,代码行数:25,代码来源:SocketIOManager.java

示例6: socket

import io.socket.client.IO; //导入依赖的package包/类
public SailsSocket socket() {
    if (url.get() == null) {
        throw new RuntimeException("Url must be initialized");
    }

    IO.Options nOptions = options.get();

    if (nOptions == null) {
        nOptions = new IO.Options();
    }

    boolean resetConnection = false;

    if (shouldResetNextConnection.get() && sailsSocket != null && !sailsSocket.isConnected()) {
        nOptions.forceNew = true;
        resetConnection = true;
    }

    if (sailsSocket == null || resetConnection) {
        sailsSocket = new SailsSocket(url.get(), options.get());
        shouldResetNextConnection.set(false);
    }

    return sailsSocket;
}
 
开发者ID:joshuamarquez,项目名称:sails.io.java,代码行数:26,代码来源:SailsIOClient.java

示例7: shouldGetErrorWhenSettingSocketOptions

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

    TestSailsSocketSingleton.getInstance().setUrl(url);
    SailsSocket sailsSocket = TestSailsSocketSingleton.getInstance().socket();
    sailsSocket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
        @Override
        public void call(Object... args) {
            try {
                TestSailsSocketSingleton.getInstance().setOptions(new IO.Options());
            } catch (Exception e) {
                assertThat(e.getMessage(), is("Can not change options while socket is connected"));
                values.offer("done");
            }
        }
    });

    sailsSocket.connect();
    values.take();
    sailsSocket.disconnect();
}
 
开发者ID:joshuamarquez,项目名称:sails.io.java,代码行数:23,代码来源:SailsSocketTest.java

示例8: testQueryOption

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

    IO.Options options = new IO.Options();
    options.query = "x-test-query-one={\"foo\":\"bar\"}";
    TestSailsSocketSingleton.getInstance().setUrl(url);
    TestSailsSocketSingleton.getInstance().setOptions(options);
    SailsSocket sailsSocket = TestSailsSocketSingleton.getInstance().socket();

    sailsSocket.get(TAG, "/queryJSON", null, buildResponseListener("get /queryJSON", values));

    sailsSocket.connect();
    values.take();
    sailsSocket.disconnect();
}
 
开发者ID:joshuamarquez,项目名称:sails.io.java,代码行数:17,代码来源:SailsSocketTest.java

示例9: connect

import io.socket.client.IO; //导入依赖的package包/类
public void connect(HashMap<String, Emitter.Listener> events) {

        mEvents = events;
        String url = mServerUrl + "/channel";

        IO.Options opts = new IO.Options();
        opts.forceNew = true;

        opts.query = "A=" + mAppId + "&C=" + mChannelId + "&S=" + mServerName + "&D=" + mDeviceId + "&U=" + xpushSession.getId();

        mChannelSocket = null;

        try {
            mChannelSocket = IO.socket(url, opts);
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }

        if (events != null) {
            for (String eventName : events.keySet()) {
                this.on(eventName, events.get(eventName));
            }
        }

        mChannelSocket.connect();
    }
 
开发者ID:xpush,项目名称:lib-xpush-android,代码行数:27,代码来源:ChannelCore.java

示例10: startMonitor

import io.socket.client.IO; //导入依赖的package包/类
@Override
public void startMonitor() {
    if (!isRunning()) {
        log.info("Starting RIPE monitor for " + prefix + " / " + host);
        IO.Options opts = new IO.Options();
        opts.path = "/stream/socket.io/";

        try {
            this.socket = IO.socket("http://stream-dev.ris.ripe.net/", opts);
            this.socket.on(Socket.EVENT_CONNECT, args -> onConnect());
            this.socket.on(Socket.EVENT_PONG, args -> socket.emit("ping"));
            this.socket.on("ris_message", this::onRisMessage);
        } catch (URISyntaxException e) {
            log.error("startMonitor()", e);
        }

        this.socket.connect();
    }
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:20,代码来源:RipeMonitors.java

示例11: Connection

import io.socket.client.IO; //导入依赖的package包/类
private Connection() {

		if ( USE_PROXY ) {
			OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
			clientBuilder.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(PROXY_SERVER, PROXY_PORT)));
			clientBuilder.proxyAuthenticator(new Authenticator() {
				@Override
				public Request authenticate(Route route, Response response) throws IOException {
					String credential = Credentials.basic(PROXY_DOMAIN + "\\" + PROXY_USER, PROXY_PASS);
					return response.request().newBuilder().header("Proxy-Authorization", credential).build();
				}
			});

			OkHttpClient client = clientBuilder.build();

			IO.setDefaultOkHttpCallFactory(client);
			IO.setDefaultOkHttpWebSocketFactory(client);
		}

		URI prefix = getPrefix();

		if ( prefix == null )
			return;

		IO.Options options = new IO.Options();
		options.reconnection = true;
		options.reconnectionDelay = 500;
		options.reconnectionDelayMax = 60000;
		options.transports = new String[]{WEBSOCKET};

		connection = IO.socket(prefix, options);

		connection.on(Socket.EVENT_CONNECT, this::onConnect);

		connection.connect();
	}
 
开发者ID:GoSuji,项目名称:Suji,代码行数:37,代码来源:Connection.java

示例12: initSocketHttp

import io.socket.client.IO; //导入依赖的package包/类
/**
 * Socket
 */
private void initSocketHttp() {

    // 休眠后會斷線… 》小米手機的神隱模式「https://kknews.cc/tech/zpav83.html」

    // 從配置文件讀取伺服器地址
    SharedPreferences settings = getSharedPreferences(data, 0);
    Hosts = settings.getString(addressField, "");

    Log.i(TAG, "initSocketHttp: Hosts: " + Hosts);

    try {
        mSocket = IO.socket(Hosts);
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    mSocket.on(Socket.EVENT_CONNECT, onConnect);
    mSocket.on(Socket.EVENT_DISCONNECT, onDisconnect);// 断开连接
    mSocket.on(Socket.EVENT_CONNECT_ERROR, onConnectError);// 连接异常
    mSocket.on(Socket.EVENT_CONNECT_TIMEOUT, onConnectTimeoutError);// 连接超时

    mSocket.on("update", onUpdate);
    mSocket.on("Ping", onPing);

    mSocket.connect();
}
 
开发者ID:qoli,项目名称:MiHomePlus,代码行数:30,代码来源:MyAccessibility.java

示例13: getIOOptions

import io.socket.client.IO; //导入依赖的package包/类
private IO.Options getIOOptions() {
  IO.Options options = new IO.Options();

  options.query = "token=" + socketToken;
  options.reconnection = true;
  options.reconnectionAttempts = 3;
  options.reconnectionDelay = 10000;
  options.reconnectionDelayMax = 60000;

  return options;
}
 
开发者ID:Juraji,项目名称:Biliomi,代码行数:12,代码来源:StreamLabsSocketSession.java

示例14: RealSocket

import io.socket.client.IO; //导入依赖的package包/类
public RealSocket() {
    try {
        this.socket =  IO.socket(GENERALSIO_API_URL);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e); // hardly possible, not enough to have an unchecked exception
    }
}
 
开发者ID:greenjoe,项目名称:sergeants,代码行数:8,代码来源:RealSocket.java

示例15: SocketConnection

import io.socket.client.IO; //导入依赖的package包/类
public SocketConnection(String namespace, JSONObject jsonObject) throws URISyntaxException {
    this.jsonObject = jsonObject;
    socket = IO.socket(namespace);
    socket.on(Socket.EVENT_CONNECT, new OnSocketConnected());
    socket.on(Socket.EVENT_DISCONNECT, new OnSocketDisconnected());
    socket.on(Socket.EVENT_ERROR, new OnSocketError());
    socket.connect();
}
 
开发者ID:Urucas,项目名称:logcatIO.lib,代码行数:9,代码来源:SocketConnection.java


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