本文整理汇总了Java中com.github.nkzawa.socketio.client.IO.socket方法的典型用法代码示例。如果您正苦于以下问题:Java IO.socket方法的具体用法?Java IO.socket怎么用?Java IO.socket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.nkzawa.socketio.client.IO
的用法示例。
在下文中一共展示了IO.socket方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupSocket
import com.github.nkzawa.socketio.client.IO; //导入方法依赖的package包/类
private void setupSocket(String server, String token) {
if (server == null) {
return;
}
if (!server.equals(connectedServer) || mSocket == null) {
teardownSocket();
try {
IO.Options opts = new IO.Options();
opts.forceNew = true;
opts.query = "token=" + token;
mSocket = IO.socket(server, opts);
setupSocketListeners();
connectedServer = server;
mSocket.connect();
} catch (URISyntaxException e) {
Log.e(TAG, "Error connecting socket.io.", e);
statusMessage(getString(R.string.server_not_connected));
}
}
}
示例2: initSocket
import com.github.nkzawa.socketio.client.IO; //导入方法依赖的package包/类
private void initSocket() {
ipAddress = PreferenceManager.getDefaultSharedPreferences(getApplication()).getString(PREF_KEY_IP_ADDRESS, null); // check if a valid IP address is already saved
// check if the IP address is valid, is so create and connect to the socket
if( ipAddress != null ){
try {
socket = IO.socket("http://"+ ipAddress +":3000"); // ip address : port no
socket.connect();
} catch (URISyntaxException e) {
Log.e(TAG, "initSocket: ", e); // log errors if any
}
}else{
Toast.makeText( getApplicationContext(), "ENTER IP", Toast.LENGTH_SHORT).show(); // display message to user that IP is invalid
}
}
示例3: WebRtcClient
import com.github.nkzawa.socketio.client.IO; //导入方法依赖的package包/类
public WebRtcClient(RtcListener listener, String host, PeerConnectionClient.PeerConnectionParameters params) {
mListener = listener;
pcParams = params;
PeerConnectionFactory.initializeAndroidGlobals(listener, true, true,
params.videoCodecHwAcceleration);
factory = new PeerConnectionFactory();
MessageHandler messageHandler = new MessageHandler();
try {
client = IO.socket(host);
} catch (URISyntaxException e) {
e.printStackTrace();
}
client.on("id", messageHandler.onId);
client.on("message", messageHandler.onMessage);
client.connect();
iceServers.add(new PeerConnection.IceServer("stun:23.21.150.121"));
iceServers.add(new PeerConnection.IceServer("stun:stun.l.google.com:19302"));
pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true"));
pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true"));
pcConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true"));
}
示例4: WebRtcClient
import com.github.nkzawa.socketio.client.IO; //导入方法依赖的package包/类
public WebRtcClient(RtcListener listener, String host, PeerConnectionParameters params, EGLContext mEGLcontext) {
mListener = listener;
pcParams = params;
// initializeAndroidGlobals的第一个参数需要是activity或者application
PeerConnectionFactory.initializeAndroidGlobals(App.getInstance(), true, true,
params.videoCodecHwAcceleration, mEGLcontext);
factory = new PeerConnectionFactory();
MessageHandler messageHandler = new MessageHandler();
try {
client = IO.socket(host);
} catch (URISyntaxException e) {
e.printStackTrace();
}
client.on("id", messageHandler.onId);
client.on("message", messageHandler.onMessage);
client.connect(); // connect后,服务端会emit一个id信息,返回该客户端的id
iceServers.add(new PeerConnection.IceServer("stun:23.21.150.121"));
iceServers.add(new PeerConnection.IceServer("stun:stun.l.google.com:19302"));
pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true"));
pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true"));
pcConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true"));
}
示例5: setupSocketIO
import com.github.nkzawa.socketio.client.IO; //导入方法依赖的package包/类
private void setupSocketIO(Server item){
try {
io = IO.socket(item.getTargetUrl());
io.on("log", new Emitter.Listener() {
@Override
public void call(Object... args) {
JSONObject dataReceive = (JSONObject) args[0];
handleMessage(dataReceive);
}
});
}catch (Exception ex){
Log.i("Exception", ex.getMessage());
}
}
示例6: initClientSocket
import com.github.nkzawa.socketio.client.IO; //导入方法依赖的package包/类
private void initClientSocket(){
try {
//socket = IO.socket("https://cloudchat-xiaominfc.c9.io");
socket = IO.socket(BASESERVERURL);
} catch (URISyntaxException e) {
e.printStackTrace();
}
bindBaseEventForSocket();
}
示例7: start
import com.github.nkzawa.socketio.client.IO; //导入方法依赖的package包/类
public void start()
{
GlobalCustomName = "";
GlobalWantsCustomName = false;
GlobalCustomColor = "";
GlobalWantsCustomColor = false;
//try to connect to the server...
try{
mSocket = IO.socket("https://palaver-server.herokuapp.com/");
//mSocket = IO.socket("http://129.21.115.31:3000/");
Log.d(TAG, "Connected");
} catch (URISyntaxException e){
Toast.makeText(this, R.string.connection_error, Toast.LENGTH_SHORT);
Log.d(TAG, "Error: Unable to connect to IP. " + e.getMessage());
}
}
示例8: Connect
import com.github.nkzawa.socketio.client.IO; //导入方法依赖的package包/类
/**
* Make the connection with the server
*
* @method Connect
*/
public void Connect(){
if(_isConnected){
return;
}
try{
Options opts = new IO.Options();
opts.port = 9000;
socket = IO.socket("http://192.168.0.2:9000",opts);
socket.connect();
OffListener();
OnConnect();
} catch (Exception e) {
Log.e("SOCKET", "Conextion expection", e);
}
}
示例9: onCreate
import com.github.nkzawa.socketio.client.IO; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
try {
mSocket = IO.socket(Constants.SERVER_IP_ADDRESS);
} catch (URISyntaxException e) {
e.printStackTrace();
}
initializeSound();
mediaPlayer.start();
isReleased = false;
}
示例10: TrackerServer
import com.github.nkzawa.socketio.client.IO; //导入方法依赖的package包/类
private TrackerServer(){
if(mSocket == null){
try{
mSocket = IO.socket("http://kalman-tracker-server.herokuapp.com");
}catch (Exception e){
e.printStackTrace();
Log.d("error connecting","to server");
}
}
}
示例11: initSocket
import com.github.nkzawa.socketio.client.IO; //导入方法依赖的package包/类
@Override
public boolean initSocket() {
UriBuilder uriBuilder = new UriBuilder();
try {
socket = IO.socket(uriBuilder.getSocketUrl().toString());
return true;
} catch (URISyntaxException e) {
SynergykitLog.print(Errors.MSG_SOCKET_INIT_FAILED);
e.printStackTrace();
return false;
}
}
示例12: SocketClient
import com.github.nkzawa.socketio.client.IO; //导入方法依赖的package包/类
/**
*
* @param address
* @param port
* @param callback
* @throws URISyntaxException
* @throws MalformedURLException
*/
public SocketClient(String address, Integer port, Long reconnectionTime, Callback callback) throws URISyntaxException, MalformedURLException {
this.callback = callback;
URL url = new URL("http", address, port, "");
IO.Options options = new IO.Options();
options.forceNew = true;
options.reconnection = true;
options.reconnectionDelay = reconnectionTime;
socket = IO.socket(url.toURI(), options);
registerEvents();
}
示例13: send
import com.github.nkzawa.socketio.client.IO; //导入方法依赖的package包/类
/**
* 回推数据
* @param handler
* @param jsonBodyStr
*/
public static synchronized void send(final String handler,final String jsonBodyStr){
Socket socket = null;
try {
LOG.debug("[Websocket Created] Prepared for connect , TIMEOUT="+TIMEOUT+" s,Delay="+DELAY);
socket = IO.socket(WSSURL);
socket.open();
int times = 0;
socket.connect();
//等待连接 超时释放
while(!socket.connected()&×*DELAY<=TIMEOUT*1000){
Thread.sleep(DELAY);
LOG.debug("[Websocket Connecting] Connecting "+(++times*0.5)+" times");
}
if(!socket.connected()){
LOG.debug("[Websocket Stop] Lost connection by timeout over "+times*0.5+" s");
if(socket!=null)socket.close();
}else{
socket.emit(handler,jsonBodyStr);
LOG.debug("[Websocket Success] Sended In "+times*0.5+" s");
}
} catch (Exception e1) {
e1.printStackTrace();
}finally {
if(socket!=null)socket.close();
socket = null;
LOG.debug("[Websocket Closed] Closed Successfully");
}
}
示例14: sendURL
import com.github.nkzawa.socketio.client.IO; //导入方法依赖的package包/类
/**
* 回推URL
* @param handler
* @param data
*/
public static synchronized void sendURL(final String handler,final Map<String,Object> data){
Socket socket = null;
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("data", data);
LOG.error("[Websocket Created "+handler+"] Prepared for connect , TIMEOUT="+TIMEOUT+" s,Delay="+DELAY);
socket = IO.socket(WSSURL);
socket.open();
int times = 0;
socket.connect();
//等待连接 超时释放
while(!socket.connected()&×*DELAY<=TIMEOUT*1000){
Thread.sleep(DELAY);
LOG.error("[Websocket Connecting] Connecting "+(++times*0.5)+" times");
}
if(!socket.connected()){
LOG.error("[Websocket Stop] Lost connection by timeout over "+times*0.5+" s");
}else{
socket.emit(handler,JsonUtil.getSuccessJsonObject(jsonObject).toJSONString());
LOG.error("[Websocket Success] Sended In "+times*0.5+" s");
}
} catch (Exception e1) {
e1.printStackTrace();
}finally {
if(socket!=null)socket.close();
socket = null;
LOG.error("[Websocket Closed] Closed Successfully");
}
}
示例15: setUp
import com.github.nkzawa.socketio.client.IO; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
socket = IO.socket(Constants.SERVER_IP_ADDRESS);
}