you need to use the platform.ready() function to know if the cordova plugins are ready to be used
see here
[TCP sockets in ionic]