【发布时间】:2012-03-02 15:29:47
【问题描述】:
我可以通过蓝牙在 PC 和 android 之间进行数据传输。但现在我想发送大小约为 80KB 的图像文件。当我发送图像时,只有一部分被传输但没有 完全地。有谁知道如何实现这一目标?我正在使用 TCP 并在 C# 平台上工作。
string fileName = "send.png";
string filePath = @"C:\Users\Asus 53s\Desktop\"; //path
byte[] fileNameByte = Encoding.ASCII.GetBytes(fileName);
byte[] fileData = File.ReadAllBytes(filePath + fileName);
byte[] clientData = new byte[4 + fileNameByte.Length + fileData.Length];
byte[] fileNameLen = BitConverter.GetBytes(fileNameByte.Length);
fileNameLen.CopyTo(clientData,0);
fileNameByte.CopyTo(clientData,4);
fileData.CopyTo(clientData,4+fileNameByte.Length);
sendMessage(clientData);
}
public Boolean sendMessage(byte[] msg)
{
{
if (!msg.Equals(""))
{
UTF8Encoding encoder = new UTF8Encoding();
NetworkStream stream = me.GetStream();
stream.Write(encoder.GetBytes(msg + "\n"), 0, (msg).Length);
stream.Flush();
}
}
【问题讨论】:
-
不发布任何代码,你怎么指望任何人都知道哪里出了问题!
-
对不起,我已经粘贴了我现在正在使用的代码。
-
收到多少图像。您可能必须以小块的形式发送它。你做了什么来找出你的代码不工作的原因。根据蓝牙的版本,它可能非常不可靠。
-
正在传输 60 KB 中的 10KB。试图分块发送。但是只有第一个块被重复发送。
标签: c# file bluetooth transfer