MjPaxter / Tcp_Socket_Connection

MIT License
10 stars 8 forks source link

Data listen not working #5

Open natheemy opened 2 years ago

natheemy commented 2 years ago

Hi, We are connecting Device camera (IOT) to sending commands and received messages was working fine for one kind of port then we are trying to connect another port to receive my video file then socket.listen is not working. how to read my video file data via socket? kindly check my below code,

TcpSocketConnection socketConnection =
           TcpSocketConnection(cameraIP, DATA_PORT);
       socketConnection.connect(5000, messageReceived);
       .then((socket) {
         if (socket != null) {
          dataSockets = socket;

           dataSockets.listen(dataHandler,
               onError: errorHandler,
              onDone: doneHandlerDone,
               cancelOnError: false);
         }
       });

void dataHandler(data) {
    builder.add(data);
    if (builder.length >= 1716980) {
      // file size
      Uint8List dt = builder.takeBytes();
      final filename = 'test1.mp4';

      // writeToFile(
      //     dt.buffer.asByteData(0, dt.buffer.lengthInBytes), '$path/$filename');
      doneHandlerDone();
    }
  }
MjPaxter commented 2 years ago

Hello! So, basically you connected and sent messages to a host and then you want to switch to another PORT, am I right? If you want to connect to another PORT, it is required to open a new TCP connection because each connection is identified uniquely with a pair (IP,PORT). It's not possible to change PORT during the connection. So, if you need to change the PORT you should open a new TcpSocketConnection connecting to that specific IP and new PORT and then listen/answer to incoming messages.

natheemy commented 2 years ago

Hi, I had already connected with another port with same host and need to write video file from the socket to device internal storage. Can you suggest the sample code to received video file? and in my case dataSockets.listen() is not being called when after sending commands.