Close connection as soon as server identity is retrieved

This is also avoiding a problem with iOS8 where only the first call to plugin will go through. Thanks to closing the connection, the plugin can be called multiple times.