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

Connection closed after first request, cannot be opened after #42

Closed
amcdevitt97 opened this issue Apr 15, 2020 · 2 comments
Closed

Connection closed after first request, cannot be opened after #42

amcdevitt97 opened this issue Apr 15, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@amcdevitt97
Copy link

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
@amcdevitt97 amcdevitt97 added the bug Something isn't working label Apr 15, 2020
@Rapsssito
Copy link
Owner

@amcdevitt97 your problem might be related to the line 63 in the client.
You call client.destroy() right after TcpSocket.createConnection(), which makes the client destroy itself immediately after creation. Try to remove that line and rethink your logic. If the issue still persists, reply back.

@amcdevitt97
Copy link
Author

This was exactly the problem. Can't believe I missed this. Thanks for responding and catching that! Going to close the issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants