當前位置: 首頁>>代碼示例>>Java>>正文


Java IO.socket方法代碼示例

本文整理匯總了Java中io.socket.client.IO.socket方法的典型用法代碼示例。如果您正苦於以下問題:Java IO.socket方法的具體用法?Java IO.socket怎麽用?Java IO.socket使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.socket.client.IO的用法示例。


在下文中一共展示了IO.socket方法的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: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: SocketApplication

import io.socket.client.IO; //導入方法依賴的package包/類
SocketApplication(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    try {
        URL = "http://" + prefs.getString("server_ip", "http://127.0.0.1/") + ":" + prefs.getString("server_port", "3000");
        socket = IO.socket(URL);
    } catch(URISyntaxException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:kedarv,項目名稱:pipette,代碼行數:10,代碼來源:SocketApplication.java

示例13: initSocket

import io.socket.client.IO; //導入方法依賴的package包/類
private void initSocket() {
    try {
        if (MainApplication.socket == null) {
            IO.Options options = new IO.Options();
            options.reconnection = false;
            MainApplication.socket = IO.socket(Constants.makeNewIpAddress(MainApplication.ServerHost) + "/msg",options);
        }
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}
 
開發者ID:whu-iss-jack,項目名稱:langren,代碼行數:12,代碼來源:MainApplication.java

示例14: connect

import io.socket.client.IO; //導入方法依賴的package包/類
public boolean connect() throws URISyntaxException {
    destroy();
    socket = IO.socket(uri, options);
    initializeSocket();
    socket.connect();
    return socket.connected();
}
 
開發者ID:aschattney,項目名稱:photostream-tools,代碼行數:8,代碼來源:AndroidSocket.java

示例15: setupSocketClient

import io.socket.client.IO; //導入方法依賴的package包/類
public void setupSocketClient() {
    IO.Options options = new IO.Options();
    options.query = "username=" +username + "&userid=" + userIdentifier;
    try {
        socketClient = IO.socket(serverURL, options);
        socketClient.connect();
        createSocketCommands();
    } catch (URISyntaxException e) {
        Log.e(TAG, "Fail to create socket: " + e.getMessage());
    }
}
 
開發者ID:brunogabriel,項目名稱:AndroidSocketChatRoom,代碼行數:12,代碼來源:ChatActivity.java


注:本文中的io.socket.client.IO.socket方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。