私は現在、TCP経由でファイルを送信する小さなプログラムを開発中です。 私はVisual Studio 2010を使用していて、プログラミング言語はVB.NETです ファイルを送信する方法は、最初にファイルをバイト配列に入れて、今考え出したとおりですが、送信する必要がありますバイト配列は一度に1バイトになるので、バイトを送信することによってどのくらいの距離があるかを知ることができます。今、私はちょうど配列から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`
コメントは議論の対象外です。この会話は[チャットに移動]されています(http://chat.stackoverflow.com/rooms/151893/discussion-on-question-by-sander-b-sending-a-byte-array-over-tcp-using-ソケット)。 –