triniwiz / nativescript-socketio

Socket.IO for nativescript
Apache License 2.0
71 stars 31 forks source link

Does not send to local tcp ip server #94

Open nitnahtnit opened 4 years ago

nitnahtnit commented 4 years ago

I'm trying to send data to a local c++ tcp/ip server listening on 127.0.0.1:27015 using:

var socket = new SocketIO("http://127.0.0.1:27015"); socket.connect();

socket.on('connect', () => console.log('connected')); socket.emit('test', 'hi');

But the server is not receiving anything. I am on same network and running from a physical android device. Can this be done? I need to send data from android to windows pc.

triniwiz commented 4 years ago

Android version ?

nitnahtnit commented 4 years ago

@triniwiz running on Android 9

triniwiz commented 4 years ago

Since you are using v9 a quick fix would be to add android:usesCleartextTraffic="true" to your application tag in the AndroidManifest but the perfect solution would be adding it to your networkSecurityConfig ..... example

triniwiz commented 4 years ago

oh I almost forgot you will need to use the ip of your computer not the localhost address

nitnahtnit commented 4 years ago

That worked well, thank you. The server is programmed to shut down once client disconnects, is there a way to keep the connection alive? SocketIO is closing connection after sending the first payload