本文整理匯總了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;
}
示例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();
}
示例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();
}
示例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();
}
}
示例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();
}
}
示例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();
}
示例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();
}
}
示例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();
}
示例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();
}
示例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
}
}
示例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();
}
示例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);
}
}
示例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();
}
}
示例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();
}
示例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());
}
}