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

closed when receiving binary data from php even if there is no code inside listen function #381

Open
glennmichaelmejias opened this issue Sep 24, 2024 · 0 comments

Comments

@glennmichaelmejias
Copy link

glennmichaelmejias commented Sep 24, 2024

rdchannel = WebSocketChannel.connect(wsUrl);

    rdchannel!.stream.listen((dynamic v) {
    
    
    } 
    

the binary data is generated in python

for i in range(8):
            for j in range(8):
                chunk_id = i * 8 + j
                left = j * chunk_width
                upper = i * chunk_height
                right = left + chunk_width
                lower = upper + chunk_height
                chunk_img = img.crop((left, upper, right, lower))
                chunk_bytes = io.BytesIO()
                chunk_img.save(chunk_bytes, format='JPEG', quality=quality)
                # Compare with the previous chunk to detect changes
                if prev_chunks.get(chunk_id) != chunk_bytes.getvalue():
                    prev_chunks[chunk_id] = chunk_bytes.getvalue()  # Update the cached chunk
                    # Prepend chunk_id to the binary data
                    chunk_with_id = struct.pack('>I', chunk_id) + chunk_bytes.getvalue()
                    changed_chunks.append(chunk_with_id)  #

        # Send only changed chunks as binary
        if changed_chunks:
            print("sent")
            for chunk in changed_chunks:
                ws.send(chunk, opcode=0x2)  

and there is no manipulation in php server, it just directly send to flutter when its received

E/flutter (31979): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: SocketException: Reading from a closed socket
E/flutter (31979): #0 _RawSecureSocket.read (dart:io/secure_socket.dart:779:7)
E/flutter (31979): #1 _Socket._onData (dart:io-patch/socket_patch.dart:2448:28)
E/flutter (31979): #2 _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter (31979): #3 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (31979): #4 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (31979): #5 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
E/flutter (31979): #6 _StreamController._add (dart:async/stream_controller.dart:658:7)
E/flutter (31979): #7 _StreamController.add (dart:async/stream_controller.dart:606:5)
E/flutter (31979): #8 _RawSecureSocket._sendReadEvent (dart:io/secure_socket.dart:1116:19)
E/flutter (31979): #9 Timer._createTimer. (dart:async-patch/timer_patch.dart:18:15)
E/flutter (31979): #10 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
E/flutter (31979): #11 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
E/flutter (31979): #12 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

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

1 participant