3

Here is the requirement:

Start a socket server in the app which will receive messages from another app running in the same device.

Here is the stack:

Using the chrome's tcpServer plugin, I ended this code:

angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
    $ionicPlatform.ready(function() {
        var tcpServer = window.chrome && window.chrome.sockets &&
            window.chrome.sockets.tcpServer;

        if(tcpServer) {  
            console.log('LOG tcpServer present')
            tcpServer.create({}, function (createInfo) {
                var serverSocketId = createInfo.socketId;
                console.log('LOG', 'serverSocketId', serverSocketId)
                if (serverSocketId > 0) {
                    tcpServer.listen(serverSocketId, '0.0.0.0', 8080, 50, function(resultCode) {
                        console.log('LOG', 'listening', resultCode)
                    });
                } else {
                  console.log('LOG', 'Unable to create socket');
                }

            });
        } else {
            console.log('LOG', 'missing chrome.sockets.tcpServer')
        }
    });
})

And the result of this code is:

LOG tcpServer present
LOG serverSocketId 0
LOG Unable to create socket

Given that I've no experience in ionic1/iOS:

  • Is this my option to create this socket server?
  • 0 means that the create method failed. What could I be doing wrong here?
  • Do I need some special permission in iOS to perform those actions? (Similar to Android)
  • I couldn't find resources/examples to help me doing this. Where should I search?

Any help is appreciated

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Rodrigo
  • 5,435
  • 5
  • 42
  • 78
  • 1
    I don't see how this is going to work; Only one app can be in the foreground at a time on iOS, so when your app is running the other app can't be sending data to it and when the other app is running your app can't be listening on a socket. – Paulw11 Jul 12 '18 at 11:40
  • @Paulw11 thanks for your comment. What about background service? Anyway, I thought exactly what you just said but couldn't find any documentation about it to confirm it. – Rodrigo Jul 12 '18 at 12:12
  • There are a few different background modes on iOS but listening on a socket isn't one of them – Paulw11 Jul 12 '18 at 12:14
  • I had similar requirement But I use the signalr or socket.io technology to handle the communication between 2 apps in the same phone and/or different phones. To use the signalr or socket.io asynchronized socket connection, you need an additional Windows Pc or linux pc. – Kenneth Li Jul 15 '18 at 09:39

0 Answers0