socketIO-client icon indicating copy to clipboard operation
socketIO-client copied to clipboard

Problem emitting binary files

Open toml01 opened this issue 9 years ago • 2 comments

Hi. I am using this library, version 2 (socketIO-client 2). I had trouble emitting binary files in chunks. this is the code:

progress = 0
dumpSize = os.stat(s_dummyDumpPath).st_size
dumpFile = open(s_dummyDumpPath, "r+b")
while True:
    piece = dumpFile.read(1024)  
    if not piece:
        # Sending finish message to server
        serverSocket.emit(s_fileSendFin, { })
        break
    progress += len(piece)
    serverSocket.emit(s_fileReq, {"name": s_dummyDumpName,"progress": progress * 100 / dumpSize, "buffer": piece})
f.close()

And I get the following error:

Traceback (most recent call last):
  File "CTedAgent.py", line 40, in <module>
    serverSocket.emit(s_fileReq, {"name": s_dummyDumpName,"progress": progress * 100 / dumpSize, "buffer": piece})
  File "/home/toml/.local/lib/python2.7/site-packages/socketIO_client/__init__.py", line 413, in emit
    self._message(str(socketIO_packet_type) + socketIO_packet_data)
  File "/home/toml/.local/lib/python2.7/site-packages/socketIO_client/__init__.py", line 26, in wrap
    return f(*args, **kw)
  File "/home/toml/.local/lib/python2.7/site-packages/socketIO_client/__init__.py", line 208, in _message
    transport.send_packet(engineIO_packet_type, engineIO_packet_data)
  File "/home/toml/.local/lib/python2.7/site-packages/socketIO_client/transports.py", line 161, in send_packet
    packet = format_packet_text(engineIO_packet_type, engineIO_packet_data)
  File "/home/toml/.local/lib/python2.7/site-packages/socketIO_client/parsers.py", line 170, in format_packet_text
    return encode_string(str(packet_type) + packet_data)
  File "/home/toml/.local/lib/python2.7/site-packages/socketIO_client/symmetries.py", line 32, in encode_string
    return x.encode('utf-8')
UnicodeDecodeError: 'ascii' codec can't decode byte 0x90 in position 30: ordinal not in range(128)

Couldn't find any answer over the web :(

toml01 avatar Oct 30 '16 22:10 toml01

We haven't gotten around to adding binary support yet.

I think @feus4177 has a fork that adds binary support. https://github.com/feus4177/socketIO-client-2

I'll try to see if we can integrate his changes in January.

invisibleroads avatar Dec 11 '16 04:12 invisibleroads

Hope in the new year,we will get the binary support by author

wwqgtxx avatar Jan 01 '17 13:01 wwqgtxx