title: React Native socket.io keeps saying
body: <p>My react native keeps saying [Error: websocket error]. I have follow some tutorial on the web but still can not get it working. Anyone know if there is a syntax error or somethig to change from this code?</p>
  
  <p>This is my full react code that i follow from this topic <a href="https://stackoverflow.com/questions/43724385/react-native-and-socket-io-node-not-working#">socket io not working</a></p>
  
  <p>ReactNative code:</p>
  
  <pre><code>import React, {Component} from 'react';
  import {
      View,
      Text,
      TouchableOpacity,
      AsyncStorage,
      StyleSheet
  } from 'react-native';
  const io = require('socket.io-client');
  
  export default class App extends Component{
      constructor(props){
          super(props);
  
          this.componentDidMount = this.componentDidMount.bind(this);
          this.onPress = this.onPress.bind(this);
      }
  
      componentDidMount () {
          const socket = io('http://localhost:3000', {
              transports: ['websocket']
          })
  
          socket.on('connect', () =&gt; {
              console.log("socket connected")
              socket.emit('YOUR EVENT TO SERVER', {})
              socket.on('EVENT YOU WANNA LISTEN', (r) =&gt; {
              })
          })
  
          socket.on('connect_error', (err) =&gt; {
              console.log(err)
          })
  
          socket.on('disconnect', () =&gt; {
              console.log("Disconnected Socket!")
          })
      }
  
      onPress(){
          // socket.emit('message', {data: 'data'});
      }
  
      render() {
          return (
              &lt;View style={{alignItems: 'center', padding: 20}}&gt;
                  &lt;Text&gt;SOCKET IO&lt;/Text&gt;
                  &lt;TouchableOpacity
                      style={{backgroundColor: '#EEE',  height: 50,  width: 200,  borderColor: 'black',  alignItems: 'center',  padding: 15}}
                      onPress={()=&gt;this.onPress()}
                  &gt;
                  &lt;Text&gt;CLICK&lt;/Text&gt;
                  &lt;/TouchableOpacity&gt;
              &lt;/View&gt;
          );
      }
  }
  </code></pre>
  
  <p>using this <code>const io = require('socket.io-client/socket.io');</code> in my case not work</p>
  
  <p>and this is my dependencies from package.json</p>
  
  <pre><code>"dependencies": {
      "react": "16.0.0-alpha.6",
      "react-native": "0.44.0",
      "socket.io-client": "^2.0.1"
    },
    "devDependencies": {
      "babel-jest": "20.0.1",
      "babel-preset-react-native": "1.9.2",
      "jest": "20.0.1",
      "react-test-renderer": "16.0.0-alpha.6"
    },
  </code></pre>