【发布时间】:2017-01-03 10:24:08
【问题描述】:
我有一台服务器,可以将文件发送给请求它们的客户端。它适用于小于 2 gigs 的文件。 但是,当文件超过 2 个演出时,我的服务器会在 Dim 缓冲区 处给我一个溢出错误。我找了一下,发现缓冲区大小可能是(upload.SendBufferSize -1)。但是,改变它会给我一个不同的错误: Upload.Send:无法立即完成非阻塞套接字操作。
我从互联网上搜索了它,一个建议是尝试添加 Upload.Blocking = True 如果发生错误,但随后我收到一个错误,提示 Argument is invalid。
对我的问题有什么建议吗?
Private Sub UploaderAccept(ar As IAsyncResult)
Dim File As IO.FileInfo = ar.AsyncState
Dim Upload As Socket = UploadServer.EndAccept(ar)
'--- Determine size of buffer
Dim fs As New IO.FileStream(File.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)
Dim buffer(Upload.SendBufferSize - 1) As Byte
Dim Sent As Long = 0
Dim t As Long = 0
'--- Actual sending
Do Until Sent >= File.Length
t = fs.Read(buffer, 0, buffer.Length)
Upload.Send(buffer, 0, t, SocketFlags.None)
Sent += t
Loop
'--- File transfer done
fs.Close()
Upload.BeginDisconnect(False, New AsyncCallback(AddressOf OnDisconnect), upload)
Upload.Close()
End Sub
【问题讨论】:
标签: file buffer send blocking transfer