GithubHelp home page GithubHelp logo

rapsssito / react-native-tcp-socket Goto Github PK

View Code? Open in Web Editor NEW
293.0 5.0 77.0 1.49 MB

React Native TCP socket API for Android, iOS & macOS with SSL/TLS support.

License: MIT License

Java 34.84% JavaScript 32.79% Objective-C 29.62% Ruby 2.75%
react-native net network tcp-socket tcp tcp-server tcp-client ios android react-native-library

react-native-tcp-socket's People

Contributors

dlguswo333 avatar eddieanthem avatar hans00 avatar jesperjohansson avatar rapsssito avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-native-tcp-socket's Issues

no client found with id X

Hi, I have problems on IOS, when I try to reuse the socket I receive:
Error in connect() function
no client found with id X

Same code is running ok on Android. First connection works ok on IOS

Connect to server without IP

Description

It's more a question that a bug.
Is it possible to connect to server by local dns os something like that? I asking for you because I'm working in a project that I won't know server IP... Actually, the server IP could be changed.

Relevant information

Library Version
OS Android & iOS
react-native 0.62.2
react-native-tcp-socket 3.5.0

Looking for maintainers

Hello everyone!
I have created react-native-tcp-socket, since the original react-native-tcp repository was abandoned long ago. As @phillbaker commented in the original repository, non active user has maintainer access on that repository, so react-native-tcp cannot be moved.

There are some forks still being actively maintained, like @aprock's one, so I wanted to ask as much react-native-tcp's forks maintainers as possible for help bringing react-native-tcp back to life in this repository.

I will post bellow a list with the maintainers I could find. If you are willing to help, reply to this issue please. Everyone is welcome!

Duplicate CocoaAsyncSocket symbols with React Native 0.62.0

Description

With React Native 0.62.0, after adding react-native-tcp-socket, you will encounter duplicate CocoaAsyncSocket symbols.

Steps to reproduce

Steps to reproduce the behavior:

  1. npx react-native init AwesomeProject --version 0.62.0
  2. cd AwesomeProject
  3. yarn add react-native-tcp-socket
  4. cd ios
  5. pod install
  6. cd ..
  7. npx react-native run-ios
  8. See error

Current behavior

You will see duplicate symbol errors being reported looking like

duplicate symbol '_OBJC_IVAR_$_GCDAsyncSocket.IsOnSocketQueueOrTargetQueueKey' in:
    /Users/mfikes/Library/Developer/Xcode/DerivedData/AwesomeProject-eadydiioyrxatngliemdjgtptiol/Build/Products/Debug-iphonesimulator/CocoaAsyncSocket/libCocoaAsyncSocket.a(GCDAsyncSocket.o)

This may also be relevant:

$ find . -name GCDAsyncSocket.m
./node_modules/react-native-tcp-socket/ios/CocoaAsyncSocket/GCDAsyncSocket.m
./ios/Pods/CocoaAsyncSocket/Source/GCD/GCDAsyncSocket.m

Expected behavior

No duplicate symbols should appear.

Relevant information

react-native 0.62.0
react-native-tcp-socket 3.4.0

Workarounds

This appears to be a consequence of Flipper, introduced in React Native 0.62.0.

Workarounds include:

  • Use React Native 0.61.5
  • Remove Flipper: Comment out the lines in ios/Podfile that enable Flipper so that the relevant section looks like:
...
  use_native_modules!

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable these next few lines.
  # add_flipper_pods!
  # post_install do |installer|
  #   flipper_post_install(installer)
  # end
...

and comment out code related to Flipper in iOS/<ProjectName>/AppDelegate.m

Unhandled error event

Description

I receive global unhandled error event causing app to crash.

Steps to reproduce

Steps to reproduce the behavior:

I am not able to reproduce. It is quite random.

Code:

  let server = TcpSocket.createServer( async function(socket) {

    socket.on('error', (err) => {
      console.warn('socket error: '+err);
      try {
        socket.destroy();
      } catch (err) {
        console.warn('Socket destroy error (on socket error): '+err);
      }
    });

    socket.on('data', async (data) => {  });

    socket.on('close', (err) => {      
      console.warn('socket closed: '+err);
    });

});

server.listen(serverOptions, () => {});

  // restart server in case of app going back to foreground
  AppState.addEventListener("change", async (state) => {
    if (state == 'active' && disabled == false) {

      if (typeof server !== 'undefined') {
         console.warn('State changed to active. Server respawned');
         try {
            server.close();
         } catch (err) {
          console.warn('Server close error on state change: '+err);
         }
         try {
            server = await createTcpServer(storage, serverOptions);
         } catch(err) {
            console.warn('Server creation error on state change: '+err);
         }
         
      }

    }
  })

Current behavior

A clear and concise description of what happened.

{
  "message": "Error: Unhandled error. (undefined)",
  "stack": [
    {
      "functionName": "emit",
      "lineNumber": 141,
      "columnNumber": 14,
      "fileName": "node_modules/events/events.js"
    },
    {
      "functionName": "_eventEmitter.addListener$argument_1",
      "lineNumber": 62,
      "columnNumber": 12,
      "fileName": "node_modules/react-native-tcp-socket/src/TcpSocket.js"
    },
    {
      "functionName": "emit",
      "lineNumber": 189,
      "columnNumber": 10,
      "fileName": "node_modules/react-native/Libraries/vendor/emitter/EventEmitter.js"
    },
    {
      "functionName": "__callFunction",
      "lineNumber": 425,
      "columnNumber": 19,
      "fileName": "node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js"
    },
    {
      "functionName": "__guard$argument_0",
      "lineNumber": 112,
      "columnNumber": 6,
      "fileName": "node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js"
    },
    {
      "functionName": "__guard",
      "lineNumber": 373,
      "columnNumber": 10,
      "fileName": "node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js"
    },
    {
      "functionName": "callFunctionReturnFlushedQueue",
      "lineNumber": 111,
      "columnNumber": 4,
      "fileName": "node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js"
    },
    {
      "functionName": "callFunctionReturnFlushedQueue",
      "lineNumber": null,
      "columnNumber": null,
      "fileName": "[native code]"
    }
  ]
}

Expected behavior

Not to crash

Relevant information

OS 13.3
react-native 0.62.2
react-native-tcp-socket 4.2.0

The server of this API accepts external connections?

Hi, i'm trying to run a socket server on a react-native project (android), that's accept external connections from a client running on a desktop (nodeJS). I already make a code, but it didn't work.

So, i just want to know if this API works for external connections or i'm miss something.

Sorry for the noob question.

> Task :react-native-tcp-socket:compileDebugJavaWithJavac FAILED

Task :react-native-tcp-socket:compileDebugJavaWithJavac FAILED
195 actionable tasks: 10 executed, 185 up-to-date
/../../../node_modules/react-native-tcp-socket/android/src/main/java/com/asterinet/react/tcpsocket/TcpSocketModule.java:74: 错误: 找不到符号
new GuardedAsyncTask<Void, Void>(mReactContext.getExceptionHandler()) {
^
符号: 方法 getExceptionHandler()
位置: 类型为ReactApplicationContext的变量 mReactContext
/../../../node_modules/react-native-tcp-socket/android/src/main/java/com/asterinet/react/tcpsocket/TcpSocketModule.java:102: 错误: 找不到符号
new GuardedAsyncTask<Void, Void>(mReactContext.getExceptionHandler()) {
^
符号: 方法 getExceptionHandler()
位置: 类型为ReactApplicationContext的变量 mReactContext
/../../../react-native-tcp-socket/android/src/main/java/com/asterinet/react/tcpsocket/TcpSocketModule.java:128: 错误: 找不到符号
new GuardedAsyncTask<Void, Void>(mReactContext.getExceptionHandler()) {
^
符号: 方法 getExceptionHandler()
位置: 类型为ReactApplicationContext的变量 mReactContext
/../../../node_modules/react-native-tcp-socket/android/src/main/java/com/asterinet/react/tcpsocket/TcpSocketModule.java:151: 错误: 找不到符号
new GuardedAsyncTask<Void, Void>(mReactContext.getExceptionHandler()) {
^
符号: 方法 getExceptionHandler()
位置: 类型为ReactApplicationContext的变量 mReactContext
注: 某些输入文件使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
4 个错误

FAILURE: Build failed with an exception.

The above problem, how do I solve it, please help and give pointers, thank you !

Incorrect iOS react-native linking for 1.2.2 due to typos in project.pbxproj

Description

Using React Native 0.59.9, after running react-native link react-native-tcp-socket and then react-native run-ios, the iOS build fails with library not found.

I was able to get it working by manually changing the iOS project.pbxproj, as it was incorrectly referencing TcpSocket.xcodeproj and libTcpSocket.a instead of TcpSockets.xcodeproj and libTcpSockets.a (so it's just a typo issue 🙂 ). See my git diff for manual fix below.

Dependencies

react-native 0.59.9
react-native-tcp-socket 1.2.2

Steps to reproduce

Steps to reproduce the behavior:

  1. Add react-native-tcp-socket 1.2.2 to package.json
  2. Run yarn install
  3. Run react-native link react-native-tcp-socket
  4. Run react-native run-ios

Current behavior

The iOS build fails with library not found as it can't find .

Expected behavior

The iOS build works 🤞

Git diff for manual fix

Diff file

diff.txt

Screenshot

Screenshot 2020-06-22 at 10 22 07

API adapters (react-native-tcp, net, tls)

We are slowly migrating to this plugin (pr here BlueWallet/BlueWallet#1223) instead of old @aprock react-native-tcp. So far so good! But we will test extensively.

I wanted to raise a concern that this package API does not conform not to nodejs net/tls nor to widely used @aprock react-native-tcp. It's no big deal, I wrote adapters, but this package cant work as a drop-in replacement out of the box. So I was thinking, maybe it's worth including adapters I wrote (https://github.com/BlueWallet/BlueWallet/pull/1223/files#diff-2054cc4c657c92ae593a544fe4dd140d) to this package so it can be a drop-in replacement?

react-native-tcp:compileDebugJavaWithJavac FAILED

Hi. On execute npm run android:

> [email protected] android C:\Users\diego\Documents\Startei - Git\FinalPointTKD\mobile
> react-native run-android

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1586 file(s) to forward-jetify. Using 4 workers...
info JS server already running.
info Installing the app...

> Configure project :react-native-orientation
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed soon. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

> Configure project :react-native-os
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed soon. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

> Configure project :react-native-tcp
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed soon. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

> Configure project :react-native-udp
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed soon. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
WARNING: The specified Android SDK Build Tools version (23.0.1) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.5.2.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '23.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
WARNING: The specified Android SDK Build Tools version (23.0.1) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.5.2.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '23.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
WARNING: The specified Android SDK Build Tools version (23.0.1) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.5.2.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '23.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

> Task :react-native-tcp:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings
92 actionable tasks: 2 executed, 90 up-to-date

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-tcp:compileDebugJavaWithJavac'.
> java.io.IOException: Unable to delete directory 'C:\Users\diego\Documents\Startei - Git\FinalPointTKD\mobile\node_modules\react-native-tcp\android\build\intermediates\javac\debug\classes'
    Failed to delete some children. This might happen because a process has files open or has its working directory set in the target directory.
    - C:\Users\diego\Documents\Startei - Git\FinalPointTKD\mobile\node_modules\react-native-tcp\android\build\intermediates\javac\debug\classes\com

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 14s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-tcp:compileDebugJavaWithJavac'.
> java.io.IOException: Unable to delete directory 'C:\Users\diego\Documents\Startei - Git\FinalPointTKD\mobile\node_modules\react-native-tcp\android\build\intermediates\javac\debug\classes'
    Failed to delete some children. This might happen because a process has files open or has its working directory set in the target directory.
    - C:\Users\diego\Documents\Startei - Git\FinalPointTKD\mobile\node_modules\react-native-tcp\android\build\intermediates\javac\debug\classes\com

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 14s

    at makeError (C:\Users\diego\Documents\Startei - Git\FinalPointTKD\mobile\node_modules\execa\index.js:174:9)
    at C:\Users\diego\Documents\Startei - Git\FinalPointTKD\mobile\node_modules\execa\index.js:278:16
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async runOnAllDevices (C:\Users\diego\Documents\Startei - Git\FinalPointTKD\mobile\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:5)
    at async Command.handleAction (C:\Users\diego\Documents\Startei - Git\FinalPointTKD\mobile\node_modules\react-native\node_modules\@react-native-community\cli\build\index.js:186:9)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] android: `react-native run-android`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] android script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\diego\AppData\Roaming\npm-cache\_logs\2020-04-22T01_25_21_932Z-debug.log

Can help me?

Server on data events stop working

Hi;
socket.on('data', (data) => { ... stops working after creating server and throwing several client requests.
Server events stop working. But the server is still running

Device Android and Android emulator (android 7 ... android 9)
"react": "16.9.0",
"react-native": "0.61.2",
"react-native-tcp-socket": "^3.0.2",

Comunication between devices

Hi, i'm trying to connect from another device to the server using the wifi direct IP, but when i try to connect the output is:

client error failed to connect to /192.168.49.1 (port 8007) from /120.0.0.1 (port 36497): connect failed: EINVAL (Invalid argument).

To get the server address ip i'm using react-native-wifi-p2p.

When i use the ip to connect from the same device of the server it work.

Execution failed for task ':react-native-tcp-socket:compileDebugJavaWithJavac'

Happens when running react-native run-android.

Output:

[Warning] Target simulator is not supported for Android platform. 
 If you want to use particular device or simulator for launching Android app,
 please specify  device id (as in 'adb devices' output) instead.

[Info] local.properties file doesn't exist. Using Android SDK location from PATH.

[Info] Starting React Native Packager.

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1202 file(s) to forward-jetify. Using 4 workers...
info Installing the app...

> Configure project :app
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

> Configure project :react-native-camera-kit
WARNING: The specified Android SDK Build Tools version (26.0.2) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.4.1.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '26.0.2'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

> Configure project :react-native-fs
WARNING: The specified Android SDK Build Tools version (26.0.3) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.4.1.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '26.0.3'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

> Configure project :rncamerakit
WARNING: The specified Android SDK Build Tools version (26.0.2) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.4.1.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '26.0.2'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

> Task :@react-native-community_async-storage:preBuild UP-TO-DATE
> Task :@react-native-community_async-storage:preDebugBuild UP-TO-DATE
> Task :@react-native-community_async-storage:checkDebugManifest
> Task :@react-native-community_async-storage:generateDebugBuildConfig
> Task :@react-native-community_async-storage:generateDebugResValues
> Task :@react-native-community_async-storage:processDebugManifest
> Task :@react-native-community_async-storage:prepareLintJar UP-TO-DATE
> Task :@react-native-community_cameraroll:preBuild UP-TO-DATE
> Task :@react-native-community_cameraroll:preDebugBuild UP-TO-DATE
> Task :@react-native-community_cameraroll:checkDebugManifest
> Task :@react-native-community_cameraroll:generateDebugBuildConfig
> Task :@react-native-community_cameraroll:generateDebugResValues
> Task :@react-native-community_cameraroll:processDebugManifest
> Task :@react-native-community_cameraroll:prepareLintJar UP-TO-DATE
> Task :app:generatePackageList
> Task :app:preBuild
> Task :react-native-camera-kit:preBuild UP-TO-DATE
> Task :react-native-camera-kit:preDebugBuild UP-TO-DATE
> Task :react-native-camera-kit:checkDebugManifest
> Task :react-native-camera-kit:processDebugManifest
> Task :react-native-fs:preBuild UP-TO-DATE
> Task :react-native-fs:preDebugBuild UP-TO-DATE
> Task :react-native-fs:checkDebugManifest
> Task :react-native-fs:processDebugManifest
> Task :react-native-gesture-handler:preBuild UP-TO-DATE
> Task :react-native-gesture-handler:preDebugBuild UP-TO-DATE
> Task :react-native-gesture-handler:checkDebugManifest
> Task :react-native-gesture-handler:processDebugManifest
> Task :react-native-reanimated:preBuild UP-TO-DATE
> Task :react-native-reanimated:preDebugBuild UP-TO-DATE
> Task :react-native-reanimated:checkDebugManifest
> Task :react-native-reanimated:processDebugManifest
> Task :react-native-safe-area-context:preBuild UP-TO-DATE
> Task :react-native-safe-area-context:preDebugBuild UP-TO-DATE
> Task :react-native-safe-area-context:checkDebugManifest
> Task :react-native-safe-area-context:processDebugManifest
> Task :react-native-screens:preBuild UP-TO-DATE
> Task :react-native-screens:preDebugBuild UP-TO-DATE
> Task :react-native-screens:checkDebugManifest
> Task :react-native-screens:processDebugManifest
> Task :react-native-tcp-socket:preBuild UP-TO-DATE
> Task :react-native-tcp-socket:preDebugBuild UP-TO-DATE
> Task :react-native-tcp-socket:checkDebugManifest
> Task :react-native-tcp-socket:processDebugManifest
> Task :react-native-vector-icons:preBuild UP-TO-DATE
> Task :react-native-vector-icons:preDebugBuild UP-TO-DATE
> Task :react-native-vector-icons:checkDebugManifest
> Task :react-native-vector-icons:processDebugManifest
> Task :react-native-wifi-p2p:preBuild UP-TO-DATE
> Task :react-native-wifi-p2p:preDebugBuild UP-TO-DATE
> Task :react-native-wifi-p2p:checkDebugManifest
> Task :react-native-wifi-p2p:processDebugManifest
> Task :rncamerakit:preBuild UP-TO-DATE
> Task :rncamerakit:preDebugBuild UP-TO-DATE
> Task :rncamerakit:checkDebugManifest UP-TO-DATE
> Task :rncamerakit:processDebugManifest
> Task :@react-native-community_async-storage:compileDebugAidl NO-SOURCE
> Task :@react-native-community_async-storage:compileDebugRenderscript NO-SOURCE
> Task :@react-native-community_async-storage:generateDebugResources
> Task :@react-native-community_async-storage:packageDebugResources
> Task :@react-native-community_async-storage:generateDebugRFile
> Task :@react-native-community_async-storage:generateDebugSources
> Task :@react-native-community_async-storage:javaPreCompileDebug
> Task :@react-native-community_async-storage:compileDebugJavaWithJavac
> Task :@react-native-community_async-storage:bundleLibCompileDebug
> Task :@react-native-community_cameraroll:compileDebugAidl NO-SOURCE
> Task :@react-native-community_cameraroll:compileDebugRenderscript NO-SOURCE
> Task :@react-native-community_cameraroll:generateDebugResources
> Task :@react-native-community_cameraroll:packageDebugResources
> Task :@react-native-community_cameraroll:generateDebugRFile
> Task :@react-native-community_cameraroll:generateDebugSources
> Task :@react-native-community_cameraroll:javaPreCompileDebug
> Task :@react-native-community_cameraroll:compileDebugJavaWithJavac
> Task :@react-native-community_cameraroll:bundleLibCompileDebug
> Task :react-native-camera-kit:compileDebugAidl NO-SOURCE
> Task :react-native-gesture-handler:compileDebugAidl NO-SOURCE
> Task :react-native-safe-area-context:compileDebugAidl NO-SOURCE
> Task :react-native-reanimated:compileDebugAidl NO-SOURCE
> Task :react-native-screens:compileDebugAidl NO-SOURCE
> Task :react-native-tcp-socket:compileDebugAidl NO-SOURCE
> Task :react-native-vector-icons:compileDebugAidl NO-SOURCE
> Task :react-native-fs:compileDebugAidl NO-SOURCE
> Task :react-native-wifi-p2p:compileDebugAidl NO-SOURCE
> Task :app:preDebugBuild
> Task :@react-native-community_async-storage:packageDebugRenderscript NO-SOURCE
> Task :rncamerakit:compileDebugAidl NO-SOURCE
> Task :app:compileDebugAidl NO-SOURCE
> Task :@react-native-community_cameraroll:packageDebugRenderscript NO-SOURCE
> Task :react-native-camera-kit:packageDebugRenderscript NO-SOURCE
> Task :react-native-fs:packageDebugRenderscript NO-SOURCE
> Task :react-native-gesture-handler:packageDebugRenderscript NO-SOURCE
> Task :react-native-reanimated:packageDebugRenderscript NO-SOURCE
> Task :react-native-safe-area-context:packageDebugRenderscript NO-SOURCE
> Task :react-native-screens:packageDebugRenderscript NO-SOURCE
> Task :react-native-tcp-socket:packageDebugRenderscript NO-SOURCE
> Task :react-native-vector-icons:packageDebugRenderscript NO-SOURCE
> Task :react-native-wifi-p2p:packageDebugRenderscript NO-SOURCE
> Task :rncamerakit:packageDebugRenderscript NO-SOURCE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:checkDebugManifest
> Task :app:generateDebugBuildConfig
> Task :app:bundleDebugJsAndAssets SKIPPED
> Task :app:prepareLintJar UP-TO-DATE
> Task :app:generateDebugSources
> Task :react-native-camera-kit:compileDebugRenderscript NO-SOURCE
> Task :react-native-camera-kit:generateDebugBuildConfig
> Task :react-native-camera-kit:generateDebugResValues
> Task :react-native-camera-kit:generateDebugResources
> Task :react-native-camera-kit:packageDebugResources
> Task :react-native-camera-kit:generateDebugRFile
> Task :react-native-camera-kit:prepareLintJar UP-TO-DATE
> Task :react-native-camera-kit:generateDebugSources
> Task :react-native-fs:compileDebugRenderscript NO-SOURCE
> Task :react-native-fs:generateDebugBuildConfig
> Task :react-native-fs:generateDebugResValues
> Task :react-native-fs:generateDebugResources
> Task :react-native-fs:packageDebugResources
> Task :react-native-fs:generateDebugRFile
> Task :react-native-fs:prepareLintJar UP-TO-DATE
> Task :react-native-fs:generateDebugSources
> Task :react-native-fs:javaPreCompileDebug

> Task :react-native-fs:compileDebugJavaWithJavac

> Task :react-native-fs:bundleLibCompileDebug
> Task :react-native-gesture-handler:compileDebugRenderscript NO-SOURCE
> Task :react-native-gesture-handler:generateDebugBuildConfig
> Task :react-native-gesture-handler:generateDebugResValues
> Task :react-native-gesture-handler:generateDebugResources
> Task :react-native-gesture-handler:packageDebugResources
> Task :react-native-gesture-handler:generateDebugRFile
> Task :react-native-gesture-handler:prepareLintJar UP-TO-DATE
> Task :react-native-gesture-handler:generateDebugSources
> Task :react-native-gesture-handler:javaPreCompileDebug

> Task :react-native-gesture-handler:compileDebugJavaWithJavac

> Task :react-native-gesture-handler:bundleLibCompileDebug
> Task :react-native-camera-kit:javaPreCompileDebug

> Task :react-native-camera-kit:compileDebugJavaWithJavac

> Task :react-native-camera-kit:bundleLibCompileDebug
> Task :react-native-reanimated:generateDebugBuildConfig
> Task :react-native-reanimated:compileDebugRenderscript NO-SOURCE
> Task :react-native-reanimated:generateDebugResValues
> Task :react-native-reanimated:generateDebugResources
> Task :react-native-reanimated:packageDebugResources
> Task :react-native-reanimated:generateDebugRFile
> Task :react-native-reanimated:prepareLintJar UP-TO-DATE
> Task :react-native-reanimated:generateDebugSources
> Task :react-native-reanimated:javaPreCompileDebug

> Task :react-native-reanimated:compileDebugJavaWithJavac

> Task :react-native-reanimated:bundleLibCompileDebug
> Task :react-native-safe-area-context:generateDebugBuildConfig
> Task :react-native-safe-area-context:compileDebugRenderscript NO-SOURCE
> Task :react-native-safe-area-context:generateDebugResValues
> Task :react-native-safe-area-context:generateDebugResources
> Task :react-native-safe-area-context:packageDebugResources
> Task :react-native-safe-area-context:generateDebugRFile
> Task :react-native-safe-area-context:prepareLintJar UP-TO-DATE
> Task :react-native-safe-area-context:generateDebugSources
> Task :react-native-safe-area-context:javaPreCompileDebug
> Task :react-native-safe-area-context:compileDebugJavaWithJavac
> Task :react-native-safe-area-context:bundleLibCompileDebug
> Task :react-native-screens:generateDebugBuildConfig
> Task :react-native-screens:compileDebugRenderscript NO-SOURCE
> Task :react-native-screens:generateDebugResValues
> Task :react-native-screens:generateDebugResources
> Task :react-native-screens:prepareLintJar UP-TO-DATE
> Task :react-native-screens:packageDebugResources
> Task :react-native-screens:generateDebugRFile
> Task :react-native-screens:generateDebugSources
> Task :react-native-screens:javaPreCompileDebug
> Task :react-native-screens:compileDebugJavaWithJavac
> Task :react-native-screens:bundleLibCompileDebug
> Task :react-native-tcp-socket:compileDebugRenderscript NO-SOURCE
> Task :react-native-tcp-socket:generateDebugBuildConfig
> Task :react-native-tcp-socket:generateDebugResValues
> Task :react-native-tcp-socket:generateDebugResources
> Task :react-native-tcp-socket:packageDebugResources
> Task :react-native-tcp-socket:generateDebugRFile
> Task :react-native-tcp-socket:prepareLintJar UP-TO-DATE
> Task :react-native-tcp-socket:generateDebugSources
> Task :react-native-tcp-socket:javaPreCompileDebug

> Task :react-native-tcp-socket:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings
100 actionable tasks: 89 executed, 11 up-to-date
Note: /Users/alexandre/Projects/socket/node_modules/react-native-fs/android/src/main/java/com/rnfs/RNFSManager.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/alexandre/Projects/socket/node_modules/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/alexandre/Projects/socket/node_modules/react-native-camera-kit/android/src/main/java/com/wix/RNCameraKit/gallery/GalleryViewManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /Users/alexandre/Projects/socket/node_modules/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NodesManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
/Users/alexandre/Projects/socket/node_modules/react-native-tcp-socket/android/src/main/java/com/asterinet/react/tcpsocket/TcpSocketModule.java:58: error: cannot find symbol
        new GuardedAsyncTask<Void, Void>(getReactApplicationContext().getExceptionHandler()) {
                                                                     ^
  symbol:   method getExceptionHandler()
  location: class ReactApplicationContext
/Users/alexandre/Projects/socket/node_modules/react-native-tcp-socket/android/src/main/java/com/asterinet/react/tcpsocket/TcpSocketModule.java:90: error: cannot find symbol
        new GuardedAsyncTask<Void, Void>(getReactApplicationContext().getExceptionHandler()) {
                                                                     ^
  symbol:   method getExceptionHandler()
  location: class ReactApplicationContext
/Users/alexandre/Projects/socket/node_modules/react-native-tcp-socket/android/src/main/java/com/asterinet/react/tcpsocket/TcpSocketModule.java:115: error: cannot find symbol
        new GuardedAsyncTask<Void, Void>(getReactApplicationContext().getExceptionHandler()) {
                                                                     ^
  symbol:   method getExceptionHandler()
  location: class ReactApplicationContext
/Users/alexandre/Projects/socket/node_modules/react-native-tcp-socket/android/src/main/java/com/asterinet/react/tcpsocket/TcpSocketModule.java:141: error: cannot find symbol
        new GuardedAsyncTask<Void, Void>(getReactApplicationContext().getExceptionHandler()) {
                                                                     ^
  symbol:   method getExceptionHandler()
  location: class ReactApplicationContext
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-tcp-socket:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2m 51s

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
Note: /Users/alexandre/Projects/socket/node_modules/react-native-fs/android/src/main/java/com/rnfs/RNFSManager.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/alexandre/Projects/socket/node_modules/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/alexandre/Projects/socket/node_modules/react-native-camera-kit/android/src/main/java/com/wix/RNCameraKit/gallery/GalleryViewManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /Users/alexandre/Projects/socket/node_modules/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NodesManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
/Users/alexandre/Projects/socket/node_modules/react-native-tcp-socket/android/src/main/java/com/asterinet/react/tcpsocket/TcpSocketModule.java:58: error: cannot find symbol
        new GuardedAsyncTask<Void, Void>(getReactApplicationContext().getExceptionHandler()) {
                                                                     ^
  symbol:   method getExceptionHandler()
  location: class ReactApplicationContext
/Users/alexandre/Projects/socket/node_modules/react-native-tcp-socket/android/src/main/java/com/asterinet/react/tcpsocket/TcpSocketModule.java:90: error: cannot find symbol
        new GuardedAsyncTask<Void, Void>(getReactApplicationContext().getExceptionHandler()) {
                                                                     ^
  symbol:   method getExceptionHandler()
  location: class ReactApplicationContext
/Users/alexandre/Projects/socket/node_modules/react-native-tcp-socket/android/src/main/java/com/asterinet/react/tcpsocket/TcpSocketModule.java:115: error: cannot find symbol
        new GuardedAsyncTask<Void, Void>(getReactApplicationContext().getExceptionHandler()) {
                                                                     ^
  symbol:   method getExceptionHandler()
  location: class ReactApplicationContext
/Users/alexandre/Projects/socket/node_modules/react-native-tcp-socket/android/src/main/java/com/asterinet/react/tcpsocket/TcpSocketModule.java:141: error: cannot find symbol
        new GuardedAsyncTask<Void, Void>(getReactApplicationContext().getExceptionHandler()) {
                                                                     ^
  symbol:   method getExceptionHandler()
  location: class ReactApplicationContext
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-tcp-socket:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2m 51s

    at checkExecSyncError (child_process.js:629:11)
    at execFileSync (child_process.js:647:13)
    at runOnAllDevices (/Users/alexandre/Projects/socket/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:74:39)
    at buildAndRun (/Users/alexandre/Projects/socket/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:158:41)
    at Object.runAndroid [as func] (/Users/alexandre/Projects/socket/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:106:12)
    at process._tickCallback (internal/process/next_tick.js:68:7)

I followed all steps from this project's README file.

build.gradle:


buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 23
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.4.1")

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
    }
}

What is the _state property?

taking a look at the interface for the TcpSocket object, it features a _state property integer that looks like it might tell me whether or not the socket is successfully connected. Wondering if that's allowed/what the number codes might be for determining that.

Server and client communication

Hi;
Thanks to your help I created a server and client connection.
The client sends a message to the server and the client returns a reply, after that I did not stop the server and do not destroy the client everything stops...

Sending an external request to the server. The data I send falls to the following area then my expectation is that the server sends this data to the connected clients.
server receives data but no client transaction

socket.on('data', (data) => {
//data arrived
socket.write( data);
});

client.on('data', function(data) {
//No move
console.log('message was received', data);
});

Platform ios ,
"react": "16.9.0",
"react-native": "0.61.4",

I hope I'm not bothering you. thank you for your attention

onClose event does not fire on connection lost

Description

onClose event doesn't fire when a TCP client loses WiFi

Steps to reproduce

Steps to reproduce the behavior:

  1. Instantiate a TCP Server on device1.
  2. Instantiate a TCP Client on device2 and connect to device1.
  3. Turn off WiFi for device2.

Current behavior

Client's socket in the TCP server is still connected.

Expected behavior

Client's socket in the TCP server must be disconnected.

Relevant information

OS ubuntu 18.04
react-native 0.61.4
react-native-tcp-socket 3.3.1

Can connect to TCP Socket Server writing on C#?

Description

I have coding TCP Socket Server on C# and installed it on windows server.
This Tcp Socket server send/receive data by bytes.

I had using react-native-tcp-socket to connect Tcp Server but failed and Tcp Server hang.
Can i using this react-native-tcp-socket on reactnative to connect Tcp server describe above?
Thanks

iOS: Server not responding after getting to background and back. No error event triggered

Description

Server not responding after getting to background and back
No error event triggered

Steps to reproduce

I have basic server configuration (simple http server). It works perfect while on foreground. If go background, it will stop responding after several seconds. It will not go back nor emit error or close event.

Options:

{
  port: 3032, 
  host: '0.0.0.0',   
  reuseAddress: true,  
}

Current behavior

As described above.

Expected behavior

I assume that error should be triggered as a clou to restart listening.

Screenshots
If applicable, add screenshots to help explain your problem.

Relevant information

OS 13.3
react-native 0.62.2
react-native-tcp-socket 4.2.0

Second socket cannot connect

Hi, I have no problems establishing a connection for the first time.
But after that first connection, I want to establish a new connection on the same port and ip, and the server socket (written in python) gets stuck on accept for this second connection.

Here is my code:

let options = {port:4444, host:self.props.ip, reuseAddress:true, localAddress:this.ipAddress, localPort:4444};
var options2 = {port:4444, host:self.props.ip, reuseAddress:true, localAddress:this.ipAddress, localPort:4444};
		
var client = TcpSocket.createConnection(options);
client.on('error', function(error) {
     console.log("error1->" + error);
});
client.write('config-' + this.ipAddress); // I receive this on the server side succesfully
client.destroy();

var client2= TcpSocket.createConnection(options2);  //this call does not trigger the accept on the server side

convertServiceException on Android on quick socket creation

After performing around 100 quick TCP Socket creation requests, Android's Connectivity Manager throws the following error:
photo5908934440569123618
It only appears when manually selecting the interface, in this case "wifi". It is related to the following code:

private void selectNetwork(final Context context, final String iface) throws InterruptedException {
/**
* Returns a network given its interface name:
* "wifi" -> WIFI
* "cellular" -> Cellular
* etc...
*/
final CountDownLatch awaitingNetwork = new CountDownLatch(1); // only needs to be counted down once to release waiting threads
final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkRequest.Builder requestBuilder = new NetworkRequest.Builder();
switch (iface) {
case "wifi":
requestBuilder.addTransportType(NetworkCapabilities.TRANSPORT_WIFI);
cm.requestNetwork(requestBuilder.build(), new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
selectedNetwork = network;
awaitingNetwork.countDown(); // Stop waiting
}
@Override
public void onUnavailable() {
awaitingNetwork.countDown(); // Stop waiting
}
});
awaitingNetwork.await();
break;
default:
selectedNetwork = cm.getActiveNetwork();
break;
}
}

iOS: No client found with id X

Description

I have problems on IOS, when I try to reuse the socket I receive:
Error in connect() function
no client found with id X

Dependencies

react-native 0.61.5
react-native-tcp-socket 3.2.4

Steps to reproduce the behavior:

calling a function like this twice.

function send()
{
         var options = {port:4444, host: x.x.x.x, reuseAddress:true, localAdress: y.y.y.y, localPort:4445}

         var client = TcpSocket.createConnection(options);
         client.on('error', function(error) {
             console.log(error)
         });
         client.on('data', function(data) {
             client.destroy();
         });
         client.write(JSON.stringify(jsArray));
}

Current behavior

if I execute the send() function once, everything works ok
second time gives the error:
Error in connect() function
no client found with id X

In android works ok every time.

Expected behavior

work ok on second try

JSON Server data convert

Hello i added an plugini and ran an application. Thank you.

Server is running and listening in this application...

I can see output when I send a post request with postman.

In the following code, how can I make an incoming requestin format in json and how to extract a json sent from an incoming query ?

server = TcpSocket.createServer((socket) => {
            this.updateChatter('server connected on ' + JSON.stringify(socket.address()));

            socket.on('data', (data) => {
             console.log(data)
                this.updateChatter('Server Received: ' + data);
            });

Migrate to a NodeJS out-of-the-box client Socket API

In the meantime, you can use these two adapters provided by BlueWallet: net API & tls API.

Error when writing Uint8Array to client

Description

I have a problem in sending byte array over TCP

componentDidMount() {
    let client;
    client = TcpSocket.createConnection(
      {
        port: Number(24),
        host: '192.168.1.104',
        // localAddress: '127.0.0.1',
        // reuseAddress: true,
        // localPort: 20000,
        // interface: "wifi"
      },
      address => {
        this.updateChatter('opened client on ' + JSON.stringify(address));
        //client.write('[101]');
        var myarray = new Uint8Array([101]);
        var buf = Buffer.alloc(1, 101);
        client.write(buf);
      },
    );

I want to send 101 as byte over TCP but my code sends 'e' character and also sending myarray throws in the following error
](http://s7.picofile.com/file/8388794926/err.jpg)
What should I do?

| OS | Android 7 |
| react-native | 0.61.5 |
| react-native-tcp-socket | ^3.2.6 |

Impossible to unregister event listener

See implementation in TcpSocket.js:

 on(event, callback) {
        switch (event) {
            case 'data':
                this._eventEmitter.addListener('data', (evt) => {
                    if (evt.id !== this._id) return;
                    const bufferTest = Buffer.from(evt.data, 'base64');
                    callback(bufferTest);
                });
                break;

Note that the listener function passed to the _eventEmitter is not the given callback, but a wrapper (evt => {.... Therefor it is impossible to use the off method to unregister the callback.

    off(event, callback) {
        this._eventEmitter.removeListener(event, callback);
    }

mReactContext.getExceptionHandler() error RN 0.60

Task :react-native-tcp-socket:compileDebugJavaWithJavac FAILED
I:\ReactProject\Project\WeixinFaceCheckIn\weixinfacecheckin\node_modules\react-native-tcp-socket\android\src\main\java\com\asterinet\react\tcpsocket\TcpSocketModule.java:107: 错误: 找不到符
号IDLE
new GuardedAsyncTask<Void, Void>(mReactContext.getExceptionHandler()) {
^
符号: 方法 getExceptionHandler()
位置: 类型为ReactApplicationContext的变量 mReactContext
I:\ReactProject\Project\WeixinFaceCheckIn\weixinfacecheckin\node_modules\react-native-tcp-socket\android\src\main\java\com\asterinet\react\tcpsocket\TcpSocketModule.java:141: 错误: 找不到符

new GuardedAsyncTask<Void, Void>(mReactContext.getExceptionHandler()) {
^
符号: 方法 getExceptionHandler()
位置: 类型为ReactApplicationContext的变量 mReactContext
I:\ReactProject\Project\WeixinFaceCheckIn\weixinfacecheckin\node_modules\react-native-tcp-socket\android\src\main\java\com\asterinet\react\tcpsocket\TcpSocketModule.java:166: 错误: 找不到符

new GuardedAsyncTask<Void, Void>(mReactContext.getExceptionHandler()) {
^
符号: 方法 getExceptionHandler()
位置: 类型为ReactApplicationContext的变量 mReactContext
I:\ReactProject\Project\WeixinFaceCheckIn\weixinfacecheckin\node_modules\react-native-tcp-socket\android\src\main\java\com\asterinet\react\tcpsocket\TcpSocketModule.java:192: 错误: 找不到符

new GuardedAsyncTask<Void, Void>(mReactContext.getExceptionHandler()) {
^
符号: 方法 getExceptionHandler()
位置: 类型为ReactApplicationContext的变量 mReactContext

编译不同过

Unable to resolve host "http://xx.xx.xx.xx"

When running, failing to get a connection to the socket I have open on my local machine. I am able to get other socket libraries connecting. I would like to get the project running and try to tweak the project example files to connect to my local server, but cannot figure out how to do so.

Here's the error I get when using this library

Unable to resolve host "http://10.0.2.2": No address associated with hostname

my Android manifest contains the required lines

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />

Import in MainAplication.java

What is the proper import ?

import com.asterinet.react.TcpSocketsModule;
or
import com.peel.react.TcpSocketsModule;

Second one is made during normal instalation

Some events are not emitted in some Android devices

Description

On some Android devices some events emitted via the sendEvent method in TcpSocketModule are not received in the JS side.
For some reason it seems to be fixed with a Thread.sleep(100) right before any event is emitted in the TcpReceiverTask. Right now I have it before the instantiating the BufferedInputStream and it doesn't fail, but I don't understand why.

Thread.sleep(100);
BufferedInputStream in = new BufferedInputStream(socket.getInputStream());
while (!isCancelled() && !socket.isClosed()) {

Do you have any idea why this could be happening?
I'm guessing it's giving time for another task in another thread to be ready for these events, but I don't know what it is.

Steps to reproduce

Steps to reproduce the behavior:
It's hard to reproduce because it doesn't happen in every device. I've got a Pixel 3 where it works perfectly and a HUAWEI MediaPad 5 where it fails quite often.

I create a connection, send the data and close it immediately.
The Pixel 3 failed 0 out of 100 events emitted.
The HUAWEI tablet failed 51 out of 100 events emitted.
The HUAWEI tablet with the Thread.sleep(100) failed 0 out of 100 events emitted.

Relevant information

| OS | Android |
| react-native | 0.62.2 |
| react-native-tcp-socket | 3.7.1 |

Reusable address

How can i set reusable address to avoid Address already in use?

Connection error never emitted on iOS

Description

Hello!!

I'm trying to create a tcp connection to an incorrect host (the ip is unreachable).

Here is my code:


...
private _device = null

private async openConnection(
        host,
        dataListenerCallback,
    ): Promise<void> {
        if (this._device) {
              this._device.destroy();
        }

        return new Promise((resolve, reject) => {
            this._device = net.createConnection({
                port: 53333,
                host,
                timeout: 1000,
            }, (socket) => {
                console.log('connected');
                resolve();
            });

            this._device.on('connect', () => {
                console.log('connect');
            });

            this._device.on('connection', () => {
                console.log('connnection');
            });

            this._device.on('error', (error) => {
                console.log('Error', error);
                reject();
            });

            this._device.on('data', dataListener);

            this._device.on('close', () => {
                console.log('Connection closed!');
            });
        });

Current behavior

this function never rejects or resolves.

Expected behavior

I expected to catch a connection error in the error event listener.

Relevant information

| react-native | 0.61.5 |
| react-native-tcp-socket | 3.7.1 |

while creating server i am getting error 'An error ocuured with the server port'

Description

A clear and concise description of what the bug is.

Steps to reproduce

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Current behavior

A clear and concise description of what happened.

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Relevant information

OS ?
react-native ?
react-native-tcp-socket ?

Connection closed after first request, cannot be opened after

Description

Client on react-native-tcp-socket will send and receive data on the first request, but all further requests are denied with error "connection closed". Is there any way to re-open this connection after the first one closes?

Code for client (React-native-tcp-socket needs updated): https://github.com/YCPRadioTelescope/rtMobile/blob/scripts/src/components/scriptsModal/scriptsModal.js
Code for the server is this "simple tcp server": https://sodocumentation.net/node-js/topic/6545/tcp-sockets

Steps to reproduce

Steps to reproduce the behavior:

  1. Run server on separate machine using 'node index.js'
  2. Download project and with android emulator open, run 'react-native run-android'
  3. Click on 'Run script', accept, run any of the given script options (all they do is send a string to the server over TCP)

Current behavior

First request reaches the server fine. Any further requests result in an "Error: Socket is closed" or "Error: Attempt to invoke virtual method void java.net.socket.connect on a null object reference". Commenting out all 'client.destroy();' lines appears to fix the problem until a second or third connection is made, then no data is sent or received at all. Almost as if the request is timing out. ('selection made' indicates the button was pressed).
Client-side:
image
Server-side:
Screen Shot 2020-04-15 at 2 26 24 PM

Expected behavior

Each time the button is pressed, a request should send to the server successfully. I'm very new to networking so if I'm doing something wrong, please let me know.

Screenshots

Client-side:
image
Server-side:
Screen Shot 2020-04-15 at 1 59 36 PM

Relevant information

OS Android v. 9 emulator
react-native 0.61.4
react-native-tcp-socket 3.5.0

[Android] onClose event not firing on both sockets

Description

close event for either client nor server doesn't fire when the other device disconnects.

Steps to reproduce

Steps to reproduce the behavior:

  1. Instantiate a TcpServer on device1 and register an event listener to the close event of the connecting socket.
  2. Create a TcpClient on device2, connect it to device1, and register an event listener to the close event of the client socket.
  3. Call .close() on either the socket connected to the TcpServer, or the one created by the TcpClient.

Current behavior

If you call .close() on the socket connected to the TcpServer, only the event listener on the TcpServer will fire, not the one if the TcpClient. Vice versa.

Expected behavior

Calling .close() on the socket will fire both the close event listeners registered on the server and client.

Relevant information

OS Android
react-native 0.61.4
react-native-tcp-socket 3.1.2

Android: SocketException error on write()

Description

Reproduction unclear- it appears to happen the first(?) time a socket connection is attempted. This does not appear to happen on iOS. I'll keep investigating and see if I can get more specifics, better repro, or create an isolated test app.

Steps to reproduce

Steps to reproduce the behavior:

  1. Attempt to connect to socket port on android
  2. See this error pop up
  3. Inbound socket traffic does not show up (outbound appears to work correctly)

Screenshots
Screen Shot 2020-02-27 at 9 26 11 PM

Relevant information

OS Android
react-native 0.61.5
react-native-tcp-socket 3.2.8

RejectedExecutionException: AsyncTask.THREAD_POOL_EXECUTOR overflowing

Description

I'm trying to implement a device detection.
To detect a device in the network I'm opening a socket and connecting to every IP address in the network: if the connection succeeds, then the device is detected.
To accomplish that I'm cycling through all IPs and I invoke a function that create a connection to the specific host.

In iOS works fine, but in Android after some sockets are opened, this failure is raised:

2020-05-06 11:07:58.476 31379-31473/com.awesomeproject E/unknown:ReactNative: Exception in native call
    java.util.concurrent.RejectedExecutionException: Task android.os.AsyncTask$3@abd3dfc rejected from java.util.concurrent.ThreadPoolExecutor@85e5c85[Running, pool size = 17, active threads = 17, queued tasks = 128, completed tasks = 59]
        at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2078)
        at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:843)
        at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1389)
        at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:651)
        at com.asterinet.react.tcpsocket.TcpSocketModule.end(TcpSocketModule.java:135)
        at com.asterinet.react.tcpsocket.TcpSocketModule.destroy(TcpSocketModule.java:141)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
        at android.os.Looper.loop(Looper.java:164)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
        at java.lang.Thread.run(Thread.java:764)

Steps to reproduce

Steps to reproduce the behavior:

for(i=0;i<ips.length;i++){
   ip = ips[i]
   port = 9600
   scanHost(ip,port).then((result) => {...}).catch((result) => {...})
}

// Function to scan hosts
const scanHost = (hostIP, hostPort) => {
    return new Promise(function (resolve, reject) {
        const client = TcpSocket.createConnection(
            {
                host: hostIP,
                port: hostPort
            }
        )

        client.on('connect', function () {
            client.end('finished')
        })

        client.on('end', function (data) {
            var scan_result = {
                success: true,
                ip: hostIP,
                port: hostPort
            }
            resolve(scan_result)
        })

       
        client.on('error', function (err) {
            var scan_result = {
                success: false,
                ip: hostIP,
                port: hostPort,
                error: err
            }
            client.destroy()
            reject(scan_result)
        })

        setTimeout(function () {

            var scan_result = {
                success: false,
                ip: hostIP,
                port: hostPort,
                error: 'Timeout (external)'
            }
            client.destroy()
            reject(scan_result)
        }, 4000)
    })
}

Relevant information

OS Android 8.0.0 Samsung SM-A530F
react-native 0.62.0
react-native-tcp-socket 3.5.0

Unknown interface for IP Address not 127.0.0.1

Description

as in #6 but the discussion around that suggests that it's only for localhost

Steps to reproduce

Steps to reproduce the behavior:

  1. Using iPhone simulator
  2. Connect to an IP address
import TcpSocket from 'react-native-tcp-socket'
this.client = TcpSocket.createConnection({port, host})

Current behavior

The socket fails to connect with error
Unknown interface. Specify valid interface by name (e.g. "en1") or IP address.

Expected behavior

The socket should connect

Relevant information

OS iOS
react-native 0.61.5
react-native-tcp-socket ^3.2.3

iOS Network Interface Issue

I'm using the following to create a connection a smart device that is hosting a TCP server on port 80. From the smart phone I connect to the broadcasted WiFi of the smart device, then initiate the following TCP connection. The same connection code works otherwise with Android.

TcpSocket.createConnection({
    host: '192.168.1.1',
    port: 80,
    localAddress: ...,
})

Per several hours of debugging and internet search I find that localAddress is required so that is why it is included otherwise I'd omit it. The problem is that when localAddress is "0.0.0.0", not specified, is "192.168.1.1", or anything other than "ap1" (current data port) then the error is:

Unknown interface. Specify valid interface by name (e.g. "en1") or IP address.

When localAddress is "127.0.0.1" or instead I supply interface as "192.168.1.1" or "ap1" then the error is:

Error in connect() function

Could this be related to: aprock/react-native-tcp#7

With many IoT and smart devices the goal during setup is that the device and the phone talk directly to each other over the smart device's WiFi access point and that the phone's cellular interface is NOT used to resolve the smart device's IP address. Any idea how to get this working cross platform?

Dependency Version
iOS latest on iPhone X device
react-native 0.61.5
react-native-tcp-socket 3.0.5

[iOS] Error: Unknown interface.

Hi;

Create server 127.0.0.1 port:9001 and create client but gives the following error.

var client = TcpSocket.createConnection({
host:"127.0.0.1",
port:9001
}, (address) => {
this.updateChatter('opened client on ' + JSON.stringify(address));
client.write('Hello, server! Love, Client.');
});

Error: Unknown interface. Specify valid interface by name (e.g. "en1") or IP address.
at normalizeError (TcpSocket.js:414)
at TcpSocket._onError (TcpSocket.js:307)
at TcpSocket.js:245
at RCTDeviceEventEmitter.emit (EventEmitter.js:189)
at MessageQueue.__callFunction (MessageQueue.js:436)
at MessageQueue.js:111
at MessageQueue.__guard (MessageQueue.js:384)
at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:110)
at debuggerWorker.js:80

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.