當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。