Closed fwaveVT closed 6 years ago
I think this is a duplicate of https://github.com/PeelTechnologies/react-native-tcp/issues/72
I was able to get the server to listen by setting the host to be the device's IP address, no idea why that's not the default. Code looks like
import TCP from 'react-native-tcp';
import { NetworkInfo } from 'react-native-network-info';
componentDidMount = () => {
NetworkInfo.getIPV4Address(ip => {
this.setState({myIpAddress: ip});
});
}
...
let server = TCP.createServer((socket) => {}).listen(PORT, this.state.myIpAddress);
Although even with that I'm having issues on iOS where socket.write() just isn't writing the data, so that's pretty cool.
Yes, that works great. For iOS devices, I guess you must discover your device's IPv4 address (e.g. using network-info) and then use that when specifying the port and host. I did it like this:
// Get IPv4 IP NetworkInfo.getIPV4Address(ipv4 => { console.log(ipv4); HOST = String(ipv4); });
then
const serverLeft = net.createServer((socket) => { / socket stuff / }) .listen({port: serverPortSensorLeft, host: HOST}, () => { console.log('ServerLeft listening to ' + JSON.stringify(serverLeft.address())); });
Thank you.
I have been able to get a tcp server to listen for connections and receive data on Android devices and the iOS simulator. However, I can't seem to get my iPhone (11.3.1) to respond no matter how I try to configure server.listen(PORT, HOST). I notice that my Android device will listen for an IPv4 client, and my iOS device an IPv6 client, but I don't think this should matter. Using RN 48.1 and Packet Sender as a test client.