2017-08-14 114 views
0

我目前正在开发一个通过TCP发送文件的小程序。 我使用的是Visual Studio 2010,编程语言是VB.NET 我希望它发送文件的方式是先将文件放入一个字节数组中,我已经想出并正在工作,但我需要发送字节数组一次一个字节,所以我可以看到它与发送字节有多远。现在我想,我可能只是从阵列中获得1个字节,并把它放在一个临时的字节数组,然后使用tcpServer.Send(tempbyte)使用VB.NET中的套接字通过TCP发送字节数组

送,但我得到的是这种错误

> `error 1 Overload resolution failed because no accessible 'Send' can 
> be called with these arguments: 
>  'Public Function Send(buffers As System.Collections.Generic.IList(Of System.ArraySegment(Of Byte))) As 
> Integer': Value of type 'Byte' cannot be converted to 
> 'System.Collections.Generic.IList(Of System.ArraySegment(Of Byte))'. 
>  'Public Function Send(buffer() As Byte) As Integer': Value of type 'Byte' cannot be converted to '1-dimensional array of 
> Byte'. C:\Users\Sander\AppData\Local\Temporary Projects\File 
> transfer\Form1.vb 40 13 File transfer` 

我怎样才能解决这个问题,因为我被困:(提前

谢谢:)

的代码我有问题:(由于某种原因,我不得不分割的代码)

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 
     Dim filename As String 
     Dim i As Integer 
     CurrentOperationLabel.Text = "Current operation: Reading file into memory..." 
     ProgressBar1.Style = ProgressBarStyle.Marquee 
     filename = System.IO.Path.GetFullPath(OpenFileDialog1.FileName) 
     Application.DoEvents() 
     Dim bytes() As Byte = IO.File.ReadAllBytes(filename) 
     FileByteLength = bytes.Length 
     Label3.Text = "Transfered bytes: 0/" & FileByteLength.ToString 



    CurrentOperationLabel.Text = "Current operation: Transfering file..." 
    ProgressBar1.Style = ProgressBarStyle.Blocks 

    Dim tempstring As String = "" 
    Dim tempbyte As Byte 
    FileByteCounter = FileByteCounter + 1 
    For i = 0 To bytes.GetUpperBound(0) 
     Application.DoEvents() 
     tempbyte = bytes(i) 
     tcpServer.Send(tempbyte) 'this is the point it fails at :/ 
     FileByteCounter = FileByteCounter + 1 
     Label3.Text = "Transfered bytes: " & FileByteCounter.ToString & "/" & FileByteLength.ToString 
     ProgressBar1.Value = FileByteCounter/FileByteLength * 100 
    Next i 

    i = 0 
    FileByteCounter = 0 
    FileByteLength = 0 
End Sub` 
+0

评论是不适合扩展讨论;这个对话已经[转移到聊天](http://chat.stackoverflow.com/rooms/151893/discussion-on-question-by-sander-b-sending-a-byte-array-over-tcp-using-一个插座)。 –

回答

0

我的问题已经解决,但解决的办法是不再相关的问题,因为视觉文森特帮了我的让我从头开始因为我希望它工作的方式如果甚至可以工作的话,它是超效率的。他提出了很多我应该做的事情,最后这一切都比我们已经拥有的代码继续工作。所以感谢Visual Vincent帮助我!