当前位置: 首页 > 知识库问答 >
问题:

反应本机udp-dgram.createSocket('udp4')错误

滕星纬
2023-03-14

我正在尝试使用react-native-udp库。
我使用expo和android studio模拟器。
我使用本手册安装此库:https://www.npmjs.com/package/react-native-udp
但是,在尝试创建套接字时发生错误。模拟器屏幕在这里。
来自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;

有什么想法吗?它不是一个未定义的错误...
完整错误输出:

null不是对象(求值'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-nativer\libraries\renderer\implementations:10696:27 in模块\react-native\libraries\renderer\implementations:307:15 in invokeGuardedCallbackImpl-Node_Modules\react-nativeRenderer-dev.js:531:36 in invokeGuardedCallback-Node_Modules\react-native\Libraries\renderer\implements:531:36 in invokeGuardedCallback-Node_Modules\react-native\Libraries\render\implements:20488:8 inentations\reactnativerEnderer-dev.js:19347:39 in workloopsync-node_modules\react-nativer\librares\renderer\implements\reactnativerEnderer-dev.js:18997:22 in renderRoot*[本机代码]:null in renderroot-node_modules\react-nativerEnderer-dev.js:18709:28 in runRootCallback*[本机代码]:null in\cjs\scheduler.development.js:643:23 in unstable_runWithPriority-node_modules\react-nativel\libraries\renderer\implementations\reactnativerrenderer-dev.js:5638:22 in flushsynccallbackqueueimpl-node_modules\react-nativerrender-dev.js:5627:28 in flushsynccallbackqueueimpl-node_modules\reactEnderer\implementations\reactnativerEnderer-dev.js:21822:15 in schedulerootate-node_modules\react-nativer\libraries\renderer\implements\reactnativerEnderer-dev.js:23042:20 in Libraries\batchedbridge\messagequee.js:436:47 in__callfunction-node_modules\react-nativels\libraries\batchedbridge\messagequee.js:111:26 in__guard$argument_0-node_modules\react-nativels\libraries\batchedbridge\messagequee.js:384:10 in__guard

警告:%s:错误边界应实现getDerivedStateFromError()。在该方法中,返回一个状态更新以显示错误消息或回退UI。rooterrorbounder-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\react-nativer\implementations:645:36 In warningWithoutStack.js:7595:16 In callCallback-node_modules\react-native\libraries\renderer\implementations\react-native\libraries\reactnativeRenderer-dev.js:7639:19 In commitupdateEffects-node_modules\react-native\libraries\reactnativeRenderer-dev.js:7630:22 Innderer\implementations\reactnativerEnderer-dev.js:20002:23 in commitlayouteffects-node_modules\react-nativer\libraries\renderer\implements\reactnativerEnderer-dev.js:307:15 in invokeGuardedCallbackimpl-node_modules\react-nativer\libraries\render\implements:531:36 in er.development.js:643:23 in unstable_runWithPriority-node_modules\react-native\libraries\renderer\implementations\reactnativeRenderer-dev.js:19590:4 in commitRoot*[本机代码]:null in commitRoot-node_modules\react-nativeRenderer-dev.js:18709:28 in runRootCallback*[本机代码]:null in runRootCallbackUment_1-node_modules\scheduler\cjs\scheduler.development.js:643:23 in unstable_runWithPriority-node_modules\react-native\libraries\renderer\implements\reactnativerrenderer-dev.js:5638:22 in flushsynccallbackqueueimpl-node_modules\react-nativerrenderer-dev.js:5627:28 in Er\implementations\reactnativerEnderer-dev.js:21822:15 in ScheduleRootedate-node_modules\react-nativer\libraries\renderer\implements\reactnativerEnderer-dev.js:23042:20 incation-node_modules\react-native\libraries\batchedbridge\messagequee.js:436:47 in__callfunction-node_modules\react-nativency\libraries\batchedbridge\messagequee.js:111:26 in__guard$argument_0-node_modules\react-native\libraries\batchedbridge\messagequee.js:384:10 in__guard

共有1个答案

陆浩博
2023-03-14
  1. 在RN项目中手动链接库。
yarn link react-native-udp
pod install
 类似资料:
  • 因此,我得到了一个错误(在底部),很可能是由于我尝试卸载react native pathjs图表引起的。以下问题只存在于android上,而不存在于ios上。 /Users/a.lau/Projects/react-native/First_App/android/app/src/main/java/com/first_app/MainApplication.java: 7:错误:找不到符号导入

  • 当我想运行反应-本机运行-Android命令我看到 失败:构建失败,有一个异常。 > 哪里出错了:配置根项目'reactNativeCliTest'时出现问题。 无法解析配置“:classpath”的所有依赖项。无法下载gradle core。jar(com.android.tools.build:gradle-core:2.2.3)无法获取资源的https://jcenter.bintray.c

  • 根据本教程,我正在将Fabric crashlytics集成到android react本机应用程序中。但是在使用安装Fabric软件包后,我尝试使用为应用程序添加午餐,但出现以下错误: 配置项目': react-nily-结构'时出现问题。 无法解析配置的所有文件: react-nate-结构: classpath。 找不到lint gradle api。jar(com.android.tool

  • 问题内容: 我正在React Native中开发一个需要使用Web Map Services的移动应用程序。我尚未找到任何允许同时使用WMS并进行本机响应的库或框架。在React(Web)中,我找到了一个。我的问题是: 您是否知道是否存在允许我使用WMS和React Native的任何库或框架,或者是否有可能在React native中集成React(web)库? 谢谢! 问题答案: 我决定使用的

  • 我正在尝试在windows上运行react native,并出现以下错误: 这将指导您如何在C:\Program Fil es\a某个项目中创建新的React-Native项目从npm安装React-Native软件包。。。事件。js:141投掷者;//未处理的“错误”事件^ 错误:在导出时生成npm enoint_进程中的errnoException(util.js:860:11)。儿童过程_手

  • 我想为我基于Web的系统开发一个自定义应用程序,以与Android和IOS一起运行。我对在我的项目中使用反应原生/expo非常初学者。我想创建一个登录页面和仪表板,以便在登录后重定向。现在我在实现堆栈导航器时遇到问题,因为我只遵循了一个youtube教程。 这是我的App.js 现在,我想首先在这里导航我的登录名。js,它位于modules/login.js 如果我尝试运行我的代码,我在cmd中遇