Rapsssito / react-native-tcp-socket

React Native TCP socket API for Android, iOS & macOS with SSL/TLS support.
MIT License
315 stars 80 forks source link

Unhandled error event while calling createConnection method #90

Closed DarshanPatel64 closed 3 years ago

DarshanPatel64 commented 3 years ago

I want to create file transfer app in react-native. I can create server using react-native-tcp-socket, but, problem arises while i try to connect the server , using createConnection method. it shows "unhandled event" error

=======================================================

startClient = () => {

    this.client = TcpSocket.createConnection({port: 12345 ,host:this.state.ip ,interface:"wifi"},
     ()=>{
      this.client.write('Hello Server');
      client.destroy();
    }
    );
      this.client.on('data', function (data) {
        console.log(data);
        this.setState({
          tmsg:data
        })
    });
  };

  startServer = () => {

    this.server = TcpSocket.createServer(function (socket) {
      socket.on('data', (data) => {
        console.log(data);
        socket.write('heeeeeeeeee');
     });

     socket.on('error', (error) => {
       console.log('An error ocurred with client socket ', error);
     });
     socket.on('close', (error) => {
      console.log('Closed connection with ', socket.address());
     });
   }).listen({port: 12345});

   this.server.on('error', (error) => {
    console.log('An error ocurred with the server', error);
   });

   this.server.on('close', () => {
    console.log('Server closed connection');
   });
  }
Rapsssito commented 3 years ago

@mrdevil64, could you try adding a listener for 'error' to this.client?

DarshanPatel64 commented 3 years ago

thanks bro!! solved : )