Skip to content

Instantly share code, notes, and snippets.

@tagrudev
Created September 13, 2012 12:42
Show Gist options
  • Save tagrudev/3714074 to your computer and use it in GitHub Desktop.
Save tagrudev/3714074 to your computer and use it in GitHub Desktop.
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