Help!! I need help with socket.io with Phonegap Build. Listening to events is not working for me.

  • 1
  • Question
  • Updated 4 years ago
I am trying to use socket.io in my phonegap build. I can connect and emit/send events/messages to the socket but the problem I am having is that the .on() events not firering. I have tried to add
<access origin="*" />
<access origin="my.ip.address.here:3000" />
<access origin="http://my.ip.address.here*" />


But that did not help. What am I doing wrong?
Please help! Your help is appreciated!
Photo of TextNinja

TextNinja

  • 10 Posts
  • 0 Reply Likes

Posted 4 years ago

  • 1
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@TextNinja,
have you tried your code with a webbrowser?
FWIW, you are not giving us enough information. Where is your Javascript in the index.html or in a separate file?

Jesse
Photo of TextNinja

TextNinja

  • 10 Posts
  • 0 Reply Likes
I just tried from a browser it doesn't work either. I am emiting from php with elephant.io and my nodejs server gets the messages but not a web browser nor phonegap app but they both can connect and emit. The javascript is inside the index.js inside the deviceready callback.


var socket = io('http://108.179.205.128:3000');

socket.on('connect', function () { alert('connected');
socket.on('myRequest', function (data) {
alert('Request Received: '+data);

});
socket.emit('welcome',{msg:"Just Connected!"});
});
Photo of TextNinja

TextNinja

  • 10 Posts
  • 0 Reply Likes
I found what the issue was. Simply Socket.io is two way communication. It's not a server you emit messages to and everyone connected to it gets them.
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@TextNinja
glad to see you moving forward.

Once, this conversation is complete, please move new conversations to
the new forum at: https://forums.adobe.com/community/phonegap/build

Thanks
Jesse
Photo of TextNinja

TextNinja

  • 10 Posts
  • 0 Reply Likes
OK. Thanks!