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.
Change the host and port inside the App.tsx to 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 a in the console to install the app on the emulator
Test the buttons and check the output in the console
Direct button will log Connected! indicating a successful connection
Library button will log an Error Printer 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.
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 thenet
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:
cd awesome-library
npm i
cd example
npm i
App.tsx
to a valid target to connect to.cd android
.\gradlew clean
cd ..
npx react-native start
a
in the console to install the app on the emulatorDirect
button will logConnected!
indicating a successful connectionLibrary
button will log an ErrorPrinter network connection timeout.
indicating a timeoutKnown 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