Java Code Examples for io.socket.client.Socket

The following examples show how to use io.socket.client.Socket. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: onos   Source File: RipeMonitors.java    License: Apache License 2.0 8 votes vote down vote up
@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();
    }
}
 
Example 2
Source Project: Socket.io-FLSocketIM-Android   Source File: VideoChatActivity.java    License: MIT License 7 votes vote down vote up
private void requestServerCreateRoom(){

        Socket socket = SocketManager.socket;
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("from_user", fromUser);
            jsonObject.put("to_user", toUser);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        socket.emit("videoChat", jsonObject, new Ack() {
            @Override
            public void call(Object... args) {

                String room = (String) args[0];
                connectRoom(room);
            }
        });
    }
 
Example 3
Source Project: Socket.io-FLSocketIM-Android   Source File: ChatActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();

    ClientManager.chattingUserId = "";
    EventBus.getDefault().unregister(this);
    KeyboardUtils.hideSoftInput(this);

    Socket socket = SocketManager.socket;
    socket.off("__join");
    socket.off("_ice_candidate");
    socket.off("_peers");
    socket.off("_new_peer");
    socket.off("_remove_peer");
    socket.off("_offer");
    socket.off("_answer");
    socket.off("cancelVideoChat");

}
 
Example 4
Source Project: Socket.io-FLSocketIM-Android   Source File: SocketManager.java    License: MIT License 6 votes vote down vote up
public static void connect(String token, final SocketCallBack callBack){

        SocketManager.callBack = callBack;
        if (socket == null) {
            initSocket(token);
        }
        else {
            socket = null;
            initSocket(token);
        }

        socket.once(Socket.EVENT_CONNECT, new Emitter.Listener() {
            @Override
            public void call(Object... args) {

                callBack.success();
            }
        });
        socket.connect();


        addHandles();
    }
 
Example 5
Source Project: LLApp   Source File: ChatFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setHasOptionsMenu(true);

        App app = (App) getActivity().getApplication();
        mSocket = app.getSocket();
        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, onConnectError);
        mSocket.on("new message", onNewMessage);
        mSocket.on("user joined", onUserJoined);
        mSocket.on("user left", onUserLeft);
        mSocket.on("typing", onTyping);
        mSocket.on("stop typing", onStopTyping);
        mSocket.connect();

//        startSignIn();
    }
 
Example 6
Source Project: LLApp   Source File: ChatFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();

    mSocket.disconnect();

    mSocket.off(Socket.EVENT_CONNECT, onConnect);
    mSocket.off(Socket.EVENT_DISCONNECT, onDisconnect);
    mSocket.off(Socket.EVENT_CONNECT_ERROR, onConnectError);
    mSocket.off(Socket.EVENT_CONNECT_TIMEOUT, onConnectError);
    mSocket.off("new message", onNewMessage);
    mSocket.off("user joined", onUserJoined);
    mSocket.off("user left", onUserLeft);
    mSocket.off("typing", onTyping);
    mSocket.off("stop typing", onStopTyping);
}
 
Example 7
public synchronized void destroy() {
    if (mSocket != null) {
        mSocket.off(Socket.EVENT_CONNECT);
        mSocket.off(Socket.EVENT_DISCONNECT);
        mSocket.off(Socket.EVENT_PING);
        mSocket.off("dataUpdate");
        mSocket.off("announcement");
        mSocket.off("alarm");
        mSocket.off("urgent_alarm");
        mSocket.off("clear_alarm");

        RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "destroy"));
        isConnected = false;
        hasWriteAuth = false;
        mSocket.disconnect();
        mSocket = null;
    }
}
 
Example 8
Source Project: socket.io-android-chat   Source File: MainFragment.java    License: MIT License 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setHasOptionsMenu(true);

    ChatApplication app = (ChatApplication) getActivity().getApplication();
    mSocket = app.getSocket();
    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, onConnectError);
    mSocket.on("new message", onNewMessage);
    mSocket.on("user joined", onUserJoined);
    mSocket.on("user left", onUserLeft);
    mSocket.on("typing", onTyping);
    mSocket.on("stop typing", onStopTyping);
    mSocket.connect();

    startSignIn();
}
 
Example 9
Source Project: socket.io-android-chat   Source File: MainFragment.java    License: MIT License 6 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();

    mSocket.disconnect();

    mSocket.off(Socket.EVENT_CONNECT, onConnect);
    mSocket.off(Socket.EVENT_DISCONNECT, onDisconnect);
    mSocket.off(Socket.EVENT_CONNECT_ERROR, onConnectError);
    mSocket.off(Socket.EVENT_CONNECT_TIMEOUT, onConnectError);
    mSocket.off("new message", onNewMessage);
    mSocket.off("user joined", onUserJoined);
    mSocket.off("user left", onUserLeft);
    mSocket.off("typing", onTyping);
    mSocket.off("stop typing", onStopTyping);
}
 
Example 10
Source Project: Socket.io-FLSocketIM-Android   Source File: VideoChatHelper.java    License: MIT License 5 votes vote down vote up
/**
 * 加入房间
 *
 * @param room 房间号
 */
private void joinRoom(String room) {

    Socket socket = SocketManager.socket;
    JSONObject object = new JSONObject();
    try {
        object.put("room", room);
    } catch (JSONException e) {

        FLLog.i("加入房间失败!!!");
        e.printStackTrace();
    }
    socket.emit("__join", object);
}
 
Example 11
Source Project: owt-client-android   Source File: SocketSignalingChannel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void disconnect() {
    if (socketIOClient != null) {
        Log.d(TAG, "Socket IO Disconnect.");
        socketIOClient.on(Socket.EVENT_DISCONNECT, onDisconnectCallback);
        socketIOClient.disconnect();
        socketIOClient = null;
    }
}
 
Example 12
Source Project: owt-client-android   Source File: SocketSignalingChannel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void disconnect() {
    if (socketIOClient != null) {
        Log.d(TAG, "Socket IO Disconnect.");
        socketIOClient.on(Socket.EVENT_DISCONNECT, onDisconnectCallback);
        socketIOClient.disconnect();
        socketIOClient = null;
    }
}
 
Example 13
Source Project: MiHomePlus   Source File: MyAccessibility.java    License: MIT License 5 votes vote down vote up
/**
 * 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();
}
 
Example 14
Source Project: zephyr   Source File: SocketService.java    License: MIT License 5 votes vote down vote up
private void setUpEvents() {
    mSocket.on(Socket.EVENT_CONNECT, args -> {
        logger.log(LogLevel.DEBUG, LOG_TAG, "Connected to server.");
        if (!preferenceManager.getBoolean(PreferenceKeys.PREF_EVER_CONNECTED_TO_SERVER)) {
            preferenceManager.putBoolean(PreferenceKeys.PREF_EVER_CONNECTED_TO_SERVER, true);
        }
        updateServiceNotification(ConnectionStatus.CONNECTED);
    }).on(Socket.EVENT_DISCONNECT, args -> {
        logger.log(LogLevel.DEBUG, LOG_TAG, "Disconnected from server.");
        updateServiceNotification(ConnectionStatus.DISCONNECTED);
    });
}
 
Example 15
Source Project: onos   Source File: ExaBgpMonitors.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void startMonitor() {
    if (!isRunning()) {
        log.info("Starting EXA monitor for " + prefix + " / " + host);
        try {
            this.socket = IO.socket("http://" + this.host + "/onos");
            this.socket.on(Socket.EVENT_CONNECT, args -> onConnect());
            this.socket.on(Socket.EVENT_PING, args -> socket.emit("pong"));
            this.socket.on("exa_message", this::onExaMessage);
        } catch (URISyntaxException e) {
            log.warn("startMonitor()", e);
        }
        this.socket.connect();
    }
}
 
Example 16
Source Project: owt-client-android   Source File: SignalingChannel.java    License: Apache License 2.0 4 votes vote down vote up
void disconnect() {
    if (socketClient != null) {
        socketClient.on(Socket.EVENT_DISCONNECT, disconnectCallback);
        socketClient.disconnect();
    }
}
 
Example 17
Source Project: 07kit   Source File: SimpleListener.java    License: GNU General Public License v3.0 4 votes vote down vote up
public Socket getSocket() {
    return clientService.getSocket();
}
 
Example 18
Source Project: 07kit   Source File: ConnectListener.java    License: GNU General Public License v3.0 4 votes vote down vote up
public ConnectListener(ClientService clientService) {
    super(Socket.EVENT_CONNECT, clientService);
}
 
Example 19
Source Project: 07kit   Source File: DisconnectListener.java    License: GNU General Public License v3.0 4 votes vote down vote up
public DisconnectListener(ClientService clientService) {
    super(Socket.EVENT_DISCONNECT, clientService);
}
 
Example 20
Source Project: 07kit   Source File: ClientService.java    License: GNU General Public License v3.0 4 votes vote down vote up
public Socket getSocket() {
    return socket;
}
 
Example 21
Source Project: LLApp   Source File: App.java    License: Apache License 2.0 4 votes vote down vote up
public Socket getSocket() {
    return mSocket;
}
 
Example 22
public void initialize() {
    dataCounter = 0;

    readPreferences();

    if (!nsAPISecret.equals(""))
        nsAPIhashCode = Hashing.sha1().hashString(nsAPISecret, Charsets.UTF_8).toString();

    RxBus.INSTANCE.send(new EventNSClientStatus("Initializing"));
    if (!NSClientPlugin.getPlugin().isAllowed()) {
        RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "not allowed"));
        RxBus.INSTANCE.send(new EventNSClientStatus("Not allowed"));
    } else if (NSClientPlugin.getPlugin().paused) {
        RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "paused"));
        RxBus.INSTANCE.send(new EventNSClientStatus("Paused"));
    } else if (!nsEnabled) {
        RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "disabled"));
        RxBus.INSTANCE.send(new EventNSClientStatus("Disabled"));
    } else if (!nsURL.equals("") && (MainApp.engineeringMode || nsURL.toLowerCase().startsWith("https://"))) {
        try {
            RxBus.INSTANCE.send(new EventNSClientStatus("Connecting ..."));
            IO.Options opt = new IO.Options();
            opt.forceNew = true;
            opt.reconnection = true;
            mSocket = IO.socket(nsURL, opt);
            mSocket.on(Socket.EVENT_CONNECT, onConnect);
            mSocket.on(Socket.EVENT_DISCONNECT, onDisconnect);
            mSocket.on(Socket.EVENT_ERROR, onError);
            mSocket.on(Socket.EVENT_CONNECT_ERROR, onError);
            mSocket.on(Socket.EVENT_CONNECT_TIMEOUT, onError);
            mSocket.on(Socket.EVENT_PING, onPing);
            RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "do connect"));
            mSocket.connect();
            mSocket.on("dataUpdate", onDataUpdate);
            mSocket.on("announcement", onAnnouncement);
            mSocket.on("alarm", onAlarm);
            mSocket.on("urgent_alarm", onUrgentAlarm);
            mSocket.on("clear_alarm", onClearAlarm);
        } catch (URISyntaxException | RuntimeException e) {
            RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "Wrong URL syntax"));
            RxBus.INSTANCE.send(new EventNSClientStatus("Wrong URL syntax"));
        }
    } else if (nsURL.toLowerCase().startsWith("http://")) {
        RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "NS URL not encrypted"));
        RxBus.INSTANCE.send(new EventNSClientStatus("Not encrypted"));
    } else {
        RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "No NS URL specified"));
        RxBus.INSTANCE.send(new EventNSClientStatus("Not configured"));
    }
}
 
Example 23
Source Project: ignite   Source File: ClusterListener.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @param client Client.
 * @param restExecutor REST executor.
 */
public ClusterListener(AgentConfiguration cfg, Socket client, RestExecutor restExecutor) {
    this.cfg = cfg;
    this.client = client;
    this.restExecutor = restExecutor;
}
 
Example 24
Source Project: socket.io-android-chat   Source File: ChatApplication.java    License: MIT License 4 votes vote down vote up
public Socket getSocket() {
    return mSocket;
}