Closed skyworms closed 3 years ago
Hard to tell without seeing your code. The example app included in the repo: https://github.com/Sifir-io/react-native-tor/blob/main/example/src/App.tsx#L79-L100 Includes an example use of the socket module. Maybe that helps, if not kindly repost with a code snippet. Thanks!
Of course. Thanks for passing along the example. That example snippet seems to work just fine for me when I run the simulator. The sample code from the README.md that I was receiving the error with is:
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, {useEffect} from 'react';
import {SafeAreaView, StatusBar} from 'react-native';
import TorBridge from 'react-native-tor';
const tor = TorBridge();
const _init = async () => {
try {
await tor.startIfNotStarted();
const target = 'kciybn4d4vuqvobdl2kdp3r2rudqbqvsymqwg4jomzft6m6gaibaf6yd.onion:50001';
const conn = await tor.createTcpConnection({ target }, (data, err) => {
if(err){
console.error('error sending msg',err);
return
}
console.log('recieved tcp msg', data);
} );
try {
await conn.write(`{ "id": 1, "method": "blockchain.scripthash.get_balance", "params": ["716decbe1660861c3d93906cb1d98ee68b154fd4d23aed9783859c1271b52a9c"] }\n`);
await conn.write(`{ "id": 2, "method": "blockchain.scripthash.get_balance", "params": ["716decbe1660861c3d93906cb1d98ee68b154fd4d23aed9783859c1271b52a9c"] }\n`);
// ... moar writes
} catch (err) {
console.error('Error SendingTcpMSg', err);
}
await conn.close();
} catch (e) {
console.log(e);
}
};
const App: () => React$Node = () => {
useEffect(() => {
_init();
}, []);
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView />
</>
);
};
export default App;
Yeah that example should be updated. To clarify, calling:
await conn.close();
Closes the TCP connection and removes any attached lsners. So :
try {
await conn.write(`{ "id": 1, "method": "blockchain.scripthash.get_balance", "params": ["716decbe1660861c3d93906cb1d98ee68b154fd4d23aed9783859c1271b52a9c"] }\n`);
await conn.write(`{ "id": 2, "method": "blockchain.scripthash.get_balance", "params": ["716decbe1660861c3d93906cb1d98ee68b154fd4d23aed9783859c1271b52a9c"] }\n`);
// ... moar writes
} catch (err) {
console.error('Error SendingTcpMSg', err);
}
await conn.close();
Will :
Makes sense ?
Ooooooh I see. Thanks for the explanation! That makes sense.
After following the installation instructions, attempting to use the Socket Usage Example in React Native on iOS results in the following error,
Sending 'torTcpStreamData' with no listeners registered.
Is there a step I may be missing?