Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket throws Error writing to stream error on iOS platform #26450

Closed
Adichilla opened this issue Sep 16, 2019 · 7 comments
Closed

Websocket throws Error writing to stream error on iOS platform #26450

Adichilla opened this issue Sep 16, 2019 · 7 comments
Labels
Bug Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@Adichilla
Copy link

Adichilla commented Sep 16, 2019

Websocket throws Error writing to stream error on iOS platform

React Native version:

React Native Environment Info:
    Fetching system and libraries information...
System:
    OS: macOS High Sierra 10.13.6
    CPU: (4) x64 Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz
    Memory: 26.56 MB / 4.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.16.3 - /usr/local/bin/node
    npm: 6.9.0 - /usr/local/bin/npm
  SDKs:
    iOS SDK:
      Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5791312
    Xcode: 10.1/10B61 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6 
    react-native: 0.60.5 => 0.60.5 
  npmGlobalPackages:
    react-native-cli: 2.0.1

Steps To Reproduce

  1. create a web socket connection in react-native using new WebSocket()
    2.once the web socket trying to connect to the server it will Throws the error

Describe what you expected to happen:

Expecting the socket to communicate the server and wait for the server response.
Added AppTransportSecurity still gets me error

Snack, code example, screenshot, or link to a repository:
https://snack.expo.io/r14899hLS

@Adichilla Adichilla added the Bug label Sep 16, 2019
@react-native-bot react-native-bot added the Platform: iOS iOS applications. label Sep 16, 2019
@react-native-bot
Copy link
Collaborator

It looks like you are using an older version of React Native. Please update to the latest release, v0.60 and verify if the issue still exists.

The "Resolution: Old Version" label will be removed automatically once you edit your original post with the results of running `react-native info` on a project using the latest release.

@Adichilla
Copy link
Author

Adichilla commented Sep 16, 2019

React native version:

info Fetching system and libraries information...
System:
    OS: macOS High Sierra 10.13.6
    CPU: (4) x64 Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz
    Memory: 26.56 MB / 4.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.16.3 - /usr/local/bin/node
    npm: 6.9.0 - /usr/local/bin/npm
  SDKs:
    iOS SDK:
      Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5791312
    Xcode: 10.1/10B61 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6 
    react-native: 0.60.5 => 0.60.5 
  npmGlobalPackages:
    react-native-cli: 2.0.1

Logs
2019-09-16 13:18:58.050064+0530 NewApp[11722:149060]SocketStream write error [0x0]: 1 9
2019-09-16 13:18:58.052 [info][tid:com.facebook.react.JavaScript] Error writing to stream
2019-09-16 13:18:58.051788+0530 NewApp[11722:149040] Error writing to stream

Upgraded to latest version of react-native still the error occurred in ios.

Source Code:

componentDidMount() {
    //websocket
    var ws = new WebSocket('ws:3.8.35.116:8002/api/socket');
    ws.onopen = () => {
      // connection opened
      ws.send('something'); // send a message
    };
    ws.onmessage = (e) => {
      // a message was received
      console.log(e.data);
    };
    ws.onerror = (e) => {
      // an error occurred
      console.log(e.message);
    };
    ws.onclose = (e) => {
      // connection closed
      console.log(e.code, e.reason);
    };
  }

WebSocket OnClose Logs

{ type: 'close',
  target: 
   { CONNECTING: 0,
     OPEN: 1,
     CLOSING: 2,
     CLOSED: 3,
     readyState: 3,
     _eventEmitter: 
      { _subscriber: 
         { _subscriptionsForType: 
            { appStateDidChange: 
               [ { subscriber: [Circular],
                   emitter: 
                    { _subscriber: [Circular],
                      _nativeModule: 
                       { getCurrentAppState: { [Function: fn] type: 'async' },
                         addListener: { [Function: fn] type: 'async' },
                         removeListeners: { [Function: fn] type: 'async' },
                         initialAppState: 'active',
                         getConstants: [Function] },
                      isAvailable: true,
                      _eventHandlers: { change: {}, memoryWarning: {} },
                      currentState: 'active' },
                   listener: [Function],
                   context: undefined,
                   eventType: 'appStateDidChange',
                   key: 0 } ],
              websocketMessage: 
               [ ,
                 ,
                 { subscriber: [Circular],
                   emitter: 
                    { _subscriber: [Circular],
                      _nativeModule: 
                       { send: { [Function: fn] type: 'async' },
                         connect: { [Function: fn] type: 'async' },
                         sendBinary: { [Function: fn] type: 'async' },
                         ping: { [Function: fn] type: 'async' },
                         close: { [Function: fn] type: 'async' },
                         addListener: { [Function: fn] type: 'async' },
                         removeListeners: { [Function: fn] type: 'async' },
                         getConstants: [Function] } },
                   listener: [Function],
                   context: undefined,
                   eventType: 'websocketMessage',
                   key: 2 },
                 { subscriber: [Circular],
                   emitter: [Circular],
                   listener: [Function],
                   context: undefined,
                   eventType: 'websocketMessage',
                   key: 3 } ],
              websocketOpen: 
               [ ,
                 ,
                 { subscriber: [Circular],
                   emitter: 
                    { _subscriber: [Circular],
                      _nativeModule: 
                       { send: { [Function: fn] type: 'async' },
                         connect: { [Function: fn] type: 'async' },
                         sendBinary: { [Function: fn] type: 'async' },
                         ping: { [Function: fn] type: 'async' },
                         close: { [Function: fn] type: 'async' },
                         addListener: { [Function: fn] type: 'async' },
                         removeListeners: { [Function: fn] type: 'async' },
                         getConstants: [Function] } },
                   listener: [Function],
                   context: undefined,
                   eventType: 'websocketOpen',
                   key: 2 },
                 { subscriber: [Circular],
                   emitter: [Circular],
                   listener: [Function],
                   context: undefined,
                   eventType: 'websocketOpen',
                   key: 3 } ],
              websocketClosed: 
               [ ,
                 ,
                 { subscriber: [Circular],
                   emitter: 
                    { _subscriber: [Circular],
                      _nativeModule: 
                       { send: { [Function: fn] type: 'async' },
                         connect: { [Function: fn] type: 'async' },
                         sendBinary: { [Function: fn] type: 'async' },
                         ping: { [Function: fn] type: 'async' },
                         close: { [Function: fn] type: 'async' },
                         addListener: { [Function: fn] type: 'async' },
                         removeListeners: { [Function: fn] type: 'async' },
                         getConstants: [Function] } },
                   listener: [Function],
                   context: undefined,
                   eventType: 'websocketClosed',
                   key: 2 },
                 { subscriber: [Circular],
                   emitter: [Circular],
                   listener: [Function],
                   context: undefined,
                   eventType: 'websocketClosed',
                   key: 3 } ],

@aleftenorio
Copy link

Hello people,

I have exactly the same error, any possible solution ???

"react-native": "0.58.5"

Thank you very much

@shiftrtech
Copy link

anyone have news with this?

@shiftrtech
Copy link

shiftrtech commented Dec 19, 2019

After testing for a while, i found the error, when i try to set the URL for socket connection i did (like yours) something like this:

new WebSocket('ws:sandbox.example.com:8080');

when a change it to:

new WebSocket('ws://sandbox.example.com:8080'); it works on android and ios.

Don't know why on android ir doesn't fail.

@stale
Copy link

stale bot commented Mar 18, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Mar 18, 2020
@stale
Copy link

stale bot commented Mar 26, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Mar 26, 2020
@facebook facebook locked as resolved and limited conversation to collaborators Mar 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

4 participants