我正在与 NAudio 合作,将音频文件 .wav 准确地从一台电脑发送到另一台电脑。
我已尝试通过网络流发送消息,但我无法检查消息是否已正确发送,因为到目前为止我在接收代码时遇到问题。
这是发送代码。
public void StartConnection()
{
_connection = new TcpClient("localhost",1111);
_stream = _connection.GetStream();
SendFile(_stream,_waveStream);
}
public void SendFile(NetworkStream StreamToWrite,WaveStream StreamToSend)
{
WaveFileWriter write = new WaveFileWriter(StreamToWrite,StreamToSend.WaveFormat);
byte[] decoded = FromStreamToByte(StreamToSend);
write.Write(decoded,0,decoded.Length);
write.Flush();
}
这是接收代码
public void ListenConnection()
{
_listener = new TcpListener(IPAddress.Any,1111);
_listener.Start();
TcpClient receiver = _listener.AcceptTcpClient();
_stream = receiver.GetStream();
}
public void ReadFile(NetworkStream stream)
{
WaveFileReader read = new WaveFileReader(stream);
}
Now i am having trouble on where to continue with receiving code because if i call read
method of read
then it asks for a byte array, offset and length. But why it asks for an array is beyond me after all its just receiving data.
Any advice on how should i proceed further with the ReadFile
method.
UPDATE---
During Debugging i found out that NetworkStream that was being passed to SendFile for use in WaveFileWriter has not determined length and so it gives the Stream Does not Support Seek Operations
. However i don't understand why it gives this error because its prototype says it can accept any Stream.