JaneaSystems / nodejs-mobile

Full-fledged Node.js on Android and iOS
https://code.janeasystems.com/nodejs-mobile
Other
2.58k stars 182 forks source link

App crashes #267

Open rachitgupta98 opened 4 years ago

rachitgupta98 commented 4 years ago

When i am trying to start the server by a button ,App crashes. Can anyone suggest the solution. @jaimecbernardo Here is my Main.js code

var rn_bridge = require('rn-bridge');

  function ser(cb) {
     const express = require('express');
     const app = express();
     const PORT = 5000;
     const server = app.listen(PORT, function () {     
      cb("server running");
     });

  const io = require('socket.io')(server);

  io.on('connection', (socket) => {
    console.log('socket connected');
    socket.on('msg', (data) => {
      console.log(data);
      socket.broadcast.emit('dash', data);
    });
  });
}

rn_bridge.channel.on('message', (msg) => {
  switch (msg) {
    case 'server':
      ser((c) => rn_bridge.channel.send(c));
      break;
    case 'client':
      rn_bridge.channel.send('node.client' + msg);
      break;
    default:
      rn_bridge.channel.send('no message');
      break;
  }
});

// // Inform react-native node is initialized.
rn_bridge.channel.send('Node was initialized.');

App.js code

<Button title="Server" onPress={() => nodejs.channel.send('server')} />

jaimecbernardo commented 4 years ago

Hi, Did you get any errors through adb logcat that could help?

rachitgupta98 commented 4 years ago

Hey @jaimecbernardo Server is successfully started but when I used ngrok and send the url through rn_bridge , app crashes with the following error.

How to solve this ???

E/nodejs: events.js:287 throw er; // Unhandled 'error' event ^

Error: spawn ./ngrok EACCES
    at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'EACCES',
  code: 'EACCES',
  syscall: 'spawn ./ngrok',
  path: './ngrok',
  spawnargs: [ 'start', '--none', '--log=stdout' ]
}

D/: HostConnection::get() New Host Connection established 0xd22aa5c0, tid 8764 E/NODEJS-MOBILE: terminating with uncaught exception of type std::ndk1::system_error: pthread_setspecific failed: Invalid argument E/NODEJS-MOBILE: /usr/local/google/buildbot/src/android/ndk-release-r20/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:73: abort_message: assertion "terminating with uncaught exception of type std::ndk1::system_error: pthread_setspecific failed: Invalid argument" failed A/libc: /usr/local/google/buildbot/src/android/ndk-release-r20/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:73: abort_message: assertion "terminating with uncaught exception of type std::__ndk1::system_error: pthread_setspecific failed: Invalid argument" failed A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 8679 (FlipperEventBas), pid 8643 (com.rn_node) Process 8643 terminated.

jaimecbernardo commented 4 years ago

Hi @rachitgupta98 , Looks like it's trying to spawn a new process, which is not supported. The error might be due to that or due to trying to access ./ngrok and you might not have permissions to the current working directory, which is / on most Android environments.

rachitgupta98 commented 4 years ago

Hi @jaimecbernardo I added read write permission in manifest.xml file but still getting the same Can you suggest any solution?

jaimecbernardo commented 4 years ago

Spawning processes is not supported, thought it might sort of work with with Android. Try to start nrgok from the full path name instead of ./nrgok. Either way, this is not a supported scenario.