发送文件思想套接字 [英] send file thought sockets
本文介绍了发送文件思想套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Visual Basic 2010中发送文件(180-220 kb)思想套接字
客户:
I''m trying to send file (180 - 220 kb) thought sockets in visual basic 2010
client :
Dim Output As New System.IO.BinaryWriter(New IO.FileStream("image.jpg", IO.FileMode.Create))
While (True)
Dim bytes(CInt(clientSocket.ReceiveBufferSize)) As Byte
serverStream.Read(bytes, 0, CInt(clientSocket.ReceiveBufferSize))
Output.Write(bytes)
if bytes.Length < 8192 then exit while
End While
Output.Close()
服务器:
server :
Dim send() As Byte = IO.File.ReadAllBytes("send.jpg")
Dim fil As Integer = send.Length
Dim til As Integer = 0
While til < fil
networkStream.Write(send, til, fil)
networkStream.Flush()
til = til + 8192
If til > fil Then Exit While
End While
但它总是发送更大的文件,然后我发送例如,如果我发送185kb文件,我将得到186kb文件
然后我的文件就是这样的图像
but it always sends biger file then i send for example if i send 185kb file i''ll get 186kb file
and then my file be like this image
推荐答案
成员7972504写道:
Member 7972504 wrote:
networkStream.Write(send,til,fil)
networkStream.Write(send, til, fil)
上一行是错误的:如果您希望发送8 kb的块,则必须写
The above line is wrong: if you wish to send 8 kb chunks then you have to write instead
chunk = 8192
While til < fil
If til-fil < 8192 Then
chunk = til-fil
End If
networkStream.Write(send, til, chunk)
til = til + chunk
End While
这篇关于发送文件思想套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文