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

undefined is not an object (evaluating 'Sockets.connect' #6

Closed
jay-cheung opened this issue Jul 9, 2016 · 6 comments
Closed

undefined is not an object (evaluating 'Sockets.connect' #6

jay-cheung opened this issue Jul 9, 2016 · 6 comments

Comments

@jay-cheung
Copy link

jay-cheung commented Jul 9, 2016

class pt extends Component {
render() {
return (

<TouchableHighlight onPress={()=> {
var net = require('react-native-tcp');
var client = new net.Socket();
let options = {
host: '192.168.0.100',
port: 9100
};
client.connect(options, function () {
console.log('Connected');
client.write('Testing Print\n');
});

            }}>
                <Text>Test</Text>
     </TouchableHighlight>
     </View>
    );
}

}
The code running fine on IOS but report
"undefined is not an object (evaluating 'Sockets.connect')"
on android

@aprock
Copy link
Contributor

aprock commented Jul 13, 2016

which version are you testing?

@jay-cheung
Copy link
Author

react-native 0.29

@aprock
Copy link
Contributor

aprock commented Jul 19, 2016

It looks like the linking steps are incorrect for android...
Can you try the following additional steps and see if this fixes it for you?

Android

...

import com.peel.react.TcpSocketsModule;     // <--- import //

public class MainActivity extends ReactActivity {
    ...

  /**
   * A list of packages used by the app. If the app uses additional views
   * or modules besides the default ones, add more packages here.
   */
  @Override
  protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new TcpSocketsModule()           // <- add here
      );
  }
}

@wean
Copy link

wean commented Jul 20, 2016

In the version 0.29.2, this function(getPackages) is moved to MainApplication.java

@aprock
Copy link
Contributor

aprock commented Jul 20, 2016

thanks @wean, I'll test that out.

@aprock
Copy link
Contributor

aprock commented Jul 20, 2016

updated the docs and sample code for 0.29.2.
#7

@aprock aprock closed this as completed Jul 20, 2016
swansontec pushed a commit to EdgeApp/react-native-tcp that referenced this issue Oct 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants