2
votes

I am trying to use react-native-udp library.
I use expo and the android studio emulator.
I used this manual to install this library: https://www.npmjs.com/package/react-native-udp
However, an error occurs when trying to create a socket. Emulator screen here.
Code from the App.js:

function App() {

var PORT = 50000;
var HOST = '0.0.0.0';
const dgram = require('dgram');
const server = dgram.createSocket('udp4');

server.on('listening', function () {
var address = server.address();
console.log('UDP Server listening on ' + address.address + ":" +
address.port);
});

server.on('message', function (message, remote) {
console.log('Message',  message);
});

server.bind(PORT, HOST);

}
export default App;

Any ideas? It is not a undefined error...
Full error output:

null is not an object (evaluating 'Sockets.createSocket') - node_modules\react-native-udp\UdpSocket.js:58:7 in UdpSocket - node_modules\react-native-udp\UdpSockets.js:10:35 in exports.createSocket * App.js:11:0 in App - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:10696:27 in renderWithHooks - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:13481:6 in mountIndeterminateComponent - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:307:15 in invokeGuardedCallbackImpl - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:531:36 in invokeGuardedCallback - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:20488:8 in beginWork$$1 - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:19370:24 in performUnitOfWork - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:19347:39 in workLoopSync - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18997:22 in renderRoot * [native code]:null in renderRoot - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18709:28 in runRootCallback * [native code]:null in runRootCallback - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5642:32 in runWithPriority$argument_1 - node_modules\scheduler\cjs\scheduler.development.js:643:23 in unstable_runWithPriority - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5638:22 in flushSyncCallbackQueueImpl - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5627:28 in flushSyncCallbackQueue - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18556:30 in scheduleUpdateOnFiber - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:21822:15 in scheduleRootUpdate - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:23042:20 in ReactNativeRenderer.render - node_modules\react-native\Libraries\ReactNative\renderApplication.js:52:52 in renderApplication - node_modules\react-native\Libraries\ReactNative\AppRegistry.js:116:10 in runnables.appKey.run - node_modules\react-native\Libraries\ReactNative\AppRegistry.js:197:26 in runApplication - node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:436:47 in __callFunction - node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:26 in __guard$argument_0 - node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:384:10 in __guard - node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:110:17 in __guard$argument_0 * [native code]:null in callFunctionReturnFlushedQueue

Warning: %s: Error boundaries should implement getDerivedStateFromError(). In that method, return a state update to display an error message or fallback UI., RootErrorBoundary - node_modules\react-native\Libraries\YellowBox\YellowBox.js:63:8 in console.error - node_modules\expo\build\environment\muteWarnings.fx.js:27:24 in error - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:645:36 in warningWithoutStack - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18056:16 in callback - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:7595:16 in callCallback - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:7639:19 in commitUpdateEffects - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:7630:22 in commitUpdateQueue - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:17116:10 in commitLifeCycles - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:20002:23 in commitLayoutEffects - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:307:15 in invokeGuardedCallbackImpl - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:531:36 in invokeGuardedCallback - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:19768:10 in commitRootImpl * [native code]:null in commitRootImpl - node_modules\scheduler\cjs\scheduler.development.js:643:23 in unstable_runWithPriority - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:19590:4 in commitRoot * [native code]:null in commitRoot - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18709:28 in runRootCallback * [native code]:null in runRootCallback - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5642:32 in runWithPriority$argument_1 - node_modules\scheduler\cjs\scheduler.development.js:643:23 in unstable_runWithPriority - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5638:22 in flushSyncCallbackQueueImpl - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5627:28 in flushSyncCallbackQueue - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18556:30 in scheduleUpdateOnFiber - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:21822:15 in scheduleRootUpdate - node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:23042:20 in ReactNativeRenderer.render - node_modules\react-native\Libraries\ReactNative\renderApplication.js:52:52 in renderApplication - node_modules\react-native\Libraries\ReactNative\AppRegistry.js:116:10 in runnables.appKey.run - node_modules\react-native\Libraries\ReactNative\AppRegistry.js:197:26 in runApplication - node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:436:47 in __callFunction - node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:26 in __guard$argument_0 - node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:384:10 in __guard - node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:110:17 in __guard$argument_0 * [native code]:null in callFunctionReturnFlushedQueue

1

1 Answers

0
votes
  1. Link the library manually in your RN project.
yarn link react-native-udp
  1. Update your pods
pod install
  1. Build for android and ios respectively.