Created
September 13, 2012 12:42
-
-
Save tagrudev/3714074 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void onCreate() { | |
Toast.makeText(getApplicationContext(), "service created", Toast.LENGTH_SHORT).show(); | |
try { | |
this.socket = new SocketIO("https://mysocketserver"); | |
SSLContext sc = SSLContext.getInstance("TLS"); | |
sc.init(null, null, null); | |
SocketIO.setDefaultSSLSocketFactory(sc); | |
} catch (MalformedURLException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} catch (NoSuchAlgorithmException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} catch (KeyManagementException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
this.socket.connect(new IOCallback() { | |
@Override | |
public void onMessage(JSONObject json, IOAcknowledge ack) { | |
} | |
@Override | |
public void onMessage(String data, IOAcknowledge ack) { | |
Log.i(TAG, "Message Received!"); | |
} | |
@Override | |
public void onError(SocketIOException socketIOException) { | |
socketIOException.printStackTrace(); | |
} | |
@Override | |
public void onDisconnect() { | |
} | |
@Override | |
public void onConnect() { | |
Log.i(TAG, "Connected!"); | |
} | |
}); | |
// This line is cached until the connection is establisched. | |
this.socket.emit("auth", someJSON()); | |
mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); | |
showNotification(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment