react-native WebSocket在Android上运行比在iOS上慢,

ufj5ltwl  于 4个月前  发布在  React
关注(0)|答案(1)|浏览(120)

Description

我的服务器代码:

const WebSocket = require('ws');
// 创建一个WebSocket服务器
const wss = new WebSocket.Server({ port: 8080 });
wss.on('connection', (ws) => {
 console.log('Client connected');
});

React native组件代码:

/**

* Sample React Native App
* [https://github.com/facebook/react-native](https://github.com/facebook/react-native)
* @Format

 */
import React, {useEffect} from 'react';
 import type {PropsWithChildren} from 'react';
 import {
 SafeAreaView,
 ScrollView,
 StatusBar,
 StyleSheet,
 Text,
 useColorScheme,
 View,
 } from 'react-native';
import {
 Colors,
 DebugInstructions,
 Header,
 LearnMoreLinks,
 ReloadInstructions,
 } from 'react-native/Libraries/NewAppScreen';
type SectionProps = PropsWithChildren<{
 title: string;
 }>;
function Section({children, title}: SectionProps): React.JSX.Element {
 const isDarkMode = useColorScheme() === 'dark';
 useEffect(() => {
 const ws = new WebSocket('ws://192.168.88.180:8080');
}, []);
 return (
 <Text
 style={[
 styles.sectionTitle,
 {
 color: isDarkMode ? Colors.white : Colors.black,
 },
 ]}>
 {title}
 <Text
 style={[
 styles.sectionDescription,
 {
 color: isDarkMode ? Colors.light : Colors.dark,
 },
 ]}>
 {children}
 </Text>);
}
function App(): React.JSX.Element {
 const isDarkMode = useColorScheme() === 'dark';
const backgroundStyle = {
 backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
 };
return (
 <StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} backgroundColor={backgroundStyle.backgroundColor} />
 <View style={{backgroundColor: isDarkMode ? Colors.black : Colors.white}}>Edit App.tsx to change this screen and then come back to see your edits. Read the docs to discover what to do next:</View>);
}
const styles = StyleSheet.create({
 sectionContainer: {marginTop: 32, paddingHorizontal: 24},
 sectionTitle: {fontSize: 24, fontWeight: '600'},
 sectionDescription: {marginTop: 8, fontSize: 18, fontWeight: '400'},
 highlight: {fontWeight: '700'},
});
export default App;
px9o7tmv

px9o7tmv1#

⚠️React Native的新版本可用!
i️您正在使用受支持的次要版本,但似乎有一个更新的补丁可用 - 0.73.7。请升级到您次要版本的最高补丁或最新版本,并验证问题是否仍然存在(或者,创建一个新项目并在其中重现问题)。如果无法重现,请告知我们,以便我们关闭此问题。这有助于确保我们关注仍在最近版本中存在的问题。

相关问题