Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么JS客户端不';无法从服务器接收二进制文件?_Javascript_Websocket_Crystal Lang - Fatal编程技术网

Javascript 为什么JS客户端不';无法从服务器接收二进制文件?

Javascript 为什么JS客户端不';无法从服务器接收二进制文件?,javascript,websocket,crystal-lang,Javascript,Websocket,Crystal Lang,服务器(水晶) Console.log显示具有字节长度且没有任何有效负载的ArrayBuffer(13) 但是!pythonclient()工作正常 from websocket import create_connection ws = create_connection("ws://[::]:3030") print("Receiving...") result = ws.recv() print("Received '%s'" % result) ws.close() 二进制接收在ch

服务器(水晶)

Console.log显示具有字节长度且没有任何有效负载的ArrayBuffer(13)

但是!pythonclient()工作正常

from websocket import create_connection
ws = create_connection("ws://[::]:3030")
print("Receiving...")
result =  ws.recv()
print("Received '%s'" % result)
ws.close()
二进制接收在chromium和firefox中不起作用。

在客户端上使用
ws.binaryType=“arraybuffer”
并将其转换为
Uint8Array

new Uint8Array(message.data) // => [72, 101, 108, 108, 111, 32, 70, 114, 111, 109, 32, 66, 105, 110, 97, 114, 121, 33]
与Crystal server发送的字节数组相匹配:

"Hello From Binary!".to_slice # => Bytes[72, 101, 108, 108, 111, 32, 70, 114, 111, 109, 32, 66, 105, 110, 97, 114, 121, 33]
在客户端上使用
ws.binaryType=“arraybuffer”
并将其转换为
Uint8Array

new Uint8Array(message.data) // => [72, 101, 108, 108, 111, 32, 70, 114, 111, 109, 32, 66, 105, 110, 97, 114, 121, 33]
与Crystal server发送的字节数组相匹配:

"Hello From Binary!".to_slice # => Bytes[72, 101, 108, 108, 111, 32, 70, 114, 111, 109, 32, 66, 105, 110, 97, 114, 121, 33]

您希望接收什么而不是数组缓冲区?您正在发送二进制数据。但是它不适用于
ws.binaryType=“blob”
ws.binaryType=“arraybuffer”
。唯一的方法是将字符串转换为arraybuffer?真正地什么…?如果您对它不满意,请将其转换为usigned int数组,然后使用它执行任何需要的操作;)您希望接收什么而不是数组缓冲区?您正在发送二进制数据。但是它不适用于
ws.binaryType=“blob”
ws.binaryType=“arraybuffer”
。唯一的方法是将字符串转换为arraybuffer?真正地什么…?如果您对它不满意,请将其转换为usigned int数组,然后使用它执行任何需要的操作;)哦,你说得对。它起作用了。但是为什么console.log(message.data)在转换到
Uint8Array
之前不向我显示有效负载呢?因为您不能。我猜它不是为了显示内容而设计的,即使在控制台中也是如此。哦,你说得对。它起作用了。但是为什么console.log(message.data)在转换到
Uint8Array
之前不向我显示有效负载呢?因为您不能。我猜它不是为了显示内容而设计的,即使在控制台中也是如此。