本文介绍了读取文件字节数已完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
伙计们
我有一个使用套接字的简单文件传输应用程序
我的问题是发送文件的字节数
此代码发送15Mb文件的整个字节,但仅发送20-40 kb的2mb文件
或750 kb的30-50 kb
我认为问题出在File.ReadAllbyte()
所以我用了Thread.Sleep(5000)
但结果是一样,变化不大
如何强制将整个文件填充为byte []?
private void StartSendingData(IPAddress ServerIP, string FileName) { Socket MySocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); byte[] bt = File.ReadAllBytes(FileName); //Thread.Sleep(5000); MySocket.Connect(new IPEndPoint(ServerIP, 33000)); MySocket.Send(bt); }
解决方案
hi guys
I have a simple File transfer application that use socket
My problem is in sending bytes of file
this code send whole byte of 15Mb file but send only 20-40 kb of 2mb file
or 30-50 kb of 750 kb
I think problem is on File.ReadAllbyte()
so i used Thread.Sleep(5000)
but result is same with little change
how to force filling whole file in byte[] ?
private void StartSendingData(IPAddress ServerIP, string FileName) { Socket MySocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); byte[] bt = File.ReadAllBytes(FileName); //Thread.Sleep(5000); MySocket.Connect(new IPEndPoint(ServerIP, 33000)); MySocket.Send(bt); }
解决方案
这篇关于读取文件字节数已完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!