-
-
Notifications
You must be signed in to change notification settings - Fork 103
Description
Description
I am currently working on a conversion of the node-thermal-printer library into a React Native library. For this, I need to replace some node modules with fitting React Native counterparts. I want to use the react-native-tcp-socket library as a substitute for the net library.
The problem that has arisen is, that the TcpSocket would not get a connection, when I try to use it in the library build by react-native-builder-bob. The same code will successfully execute, if put in a function directly inside the app, though.
In my case, I'm using a printer that is connected in the same network as my PC.
I have built an example as minimal as possible for this problem, so it can be easily reproduced.
Steps to reproduce
Steps to reproduce the behavior:
- Clone my minimal example repository
- Go inside the repository:
cd awesome-library - Install and build package:
npm i - Go inside the example folder:
cd example - Install the example App:
npm i - Change the host and port inside the
App.tsxto a valid target to connect to. - Go inside the android folder:
cd android - Build the project with Gradle:
.\gradlew clean - Go back into the example folder:
cd .. - Start an android emulator
- Start the app in the console:
npx react-native start - Press
ain the console to install the app on the emulator - Test the buttons and check the output in the console
Directbutton will logConnected!indicating a successful connectionLibrarybutton will log an ErrorPrinter network connection timeout.indicating a timeout
Known issue
When pressing the library button and then the direct button afterward, an error is displayed the first time:
ERROR Printer network connection error: connect() called twice with the same id.
Current behavior
The TcpSocket.createConnection() method times out, every time it is used from inside a self build library, when the same connection
works from inside the app directly.
Expected behavior
The TcpSocket.createConnection() method should behave the same when used inside a self build library or when used directly in the app.
Relevant information
| OS | Windows/Android |
| react-native | 0.74.3 |
| react-native-tcp-socket | ^6.2.0 |