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