请教关于netstream的问题,请大侠帮忙
我的意思是在发送netstream是在流前加流的长度并用"|"与流分隔,接受时先接受12个byte,并转为string,读出发送流的长度,在将12个byte里除了流长度和“|”剩余的byte拷贝到allbyte(),再将剩余的流读出液放入到allbyte,然后转为文本
可却发现问题:只能传输大小为9571的文本,再大的话就显示空格,但目标文本大小与原文本大小相同
请问是什么原因,请赐教
Sub send()
Dim client As New Sockets.TcpClient("monica", 6605)
Dim sendstream As Sockets.NetworkStream
sendstream = client.GetStream
Dim sendfile As New IO.FileStream("f:\so.txt", IO.FileMode.Open)
Dim defbyte(sendfile.Length - 1) As Byte
sendfile.Read(defbyte, 0, defbyte.Length)
sendfile.Close()
Dim bytelen() As Byte
bytelen = Encoding.Default.GetBytes(defbyte.Length.ToString & "|")
Dim sendbyte(defbyte.Length + bytelen.Length - 1) As Byte
bytelen.CopyTo(sendbyte, 0)
defbyte.CopyTo(sendbyte, bytelen.Length)
MsgBox("发送文件" & sendbyte.Length)
sendstream.Write(sendbyte, 0, sendbyte.Length)
sendfile.Close()
client.Close()
End Sub
Sub listen()
listener.Start()
While True
Dim server As New Sockets.TcpClient()
server = listener.AcceptTcpClient
Dim recstream As Sockets.NetworkStream
recstream = server.GetStream
Dim realbytecount As Integer = 0
Dim firstread(11) As Byte
recstream.Read(firstread, 0, 12)
Dim str As String
str = Encoding.Default.GetString(firstread)
realbytecount = Mid(str, 1, str.IndexOf("|"))
Dim yu As Integer = 12 - realbytecount.ToString.Length - 1
Dim secondread(realbytecount + realbytecount.ToString.Length - 12) As Byte
Dim allbyte(realbytecount - 1) As Byte
firstread.Copy(firstread, realbytecount.ToString.Length + 1, allbyte, 0, yu)
recstream.Read(secondread, 0, secondread.Length)
secondread.CopyTo(allbyte, yu)
recstream.Close()
server.Close()
Dim recfile As New IO.FileStream("f:\kill.txt", IO.FileMode.Create)
recfile.Write(allbyte, 0, allbyte.Length)
recfile.Close()
End While
End Sub
其余代码省略