I'm working on a simple file and folder transfer program in c# using the tcp protocol.
The method I use to transfer a file is to divide it into small pieces. Each of these pieces will be encoded in Base64 and inserted into a more complex JSON message which will then be sent to the other side. So every message will always be in text form thanks to Base64.
I don't have much experience with networks and I decided to make this choice because reading on the internet, sending a stream of bytes without any coding could risk that some part of the message could be interpreted by the router or firewall as a command risking interrupt the connection.
My problem is that my software also works with very large files (> 10GB) and the base64 encoding only increases the data size and makes the transfer very slow because the cpu works so much to encode/decode continuously.
Now I would like to know:
答案 0 :(得分:4)
例如,发送仅以字节为单位转换而未先以任何格式进行编码的简单文件,是否确实会对路由器或防火墙造成问题?
一点也不。这样做是完全正常的,例如所有HTTPS通信都是二进制的-并且可以正常工作。
使用Base64进行大文件传输是否正确?
虽然可以做到这一点,但是如果基础层支持二进制数据,这将是无用的开销。
还有更好的选择吗?
直接使用二进制。不要编码或解码任何东西。不要将其包装到JSON这类实际上不需要传输的层中。