none
用socket傳送超過 8192k 的檔案 RRS feed

  • 問題

  • 請問一下各位高手 ,小弟在寫一個用socket 傳圖片的程式,不過超過8k的檔案就會接收不完全

    我爬文知道 socket的 buffer是 8192k 所以好像超過8192k就要分開接,不過小弟想不出方法

    以下是我的程式碼,想請問各位高手那邊有錯呢,請指點一下謝謝了

     

    Dim fs As New IO.FileStream(SaveFileDialog1.FileName, IO.FileMode.OpenOrCreate)
                Dim rebyte(400000) As Byte
                Dim myhostsocket As Socket = receivesocket.Accept()
                Dim wr As New BinaryWriter(fs)
                Dim offset, recv_num As Integer

                offset = 0

                While True
                    recv_num = myhostsocket.Receive(rebyte)
                    TextBox1.Text = recv_num

                    If recv_num <= 0 Then
                        Exit While
                    End If

                    Windows.Forms.MessageBox.Show(offset.ToString() + " " + recv_num.ToString())
                    wr.Write(rebyte, offset, recv_num)
                    offset += recv_num
                End While

                'wr.Write(rebyte, 0, rebyte.Length - 1)
                fs.Close()
              

    2008年12月11日 上午 10:22