文字列形式のリストビューでユーザー名を取得しようとしています。私がやりたいのは、これらのユーザー名を取得して文字列の配列に保存し、ネットワーク経由で送信して、受信側がそれらを抽出してそれらのユーザー名をリストビューに配置できるようにすることです。
しかし問題は、ネットワーク経由で文字列の配列を送信するのがうまくいかないことです。ネットワーク経由で文字列を送信する方法は知っていますが、ネットワーク経由で文字列の配列を送信する方法がわかりません。
私が考えているのは、ループを使用して文字列を保存および抽出する必要があるのでしょうか。しかし、私はそれを行う方法を正確に知りません。
送信用のコードは次のとおりです。
'Say, this array contains the following strings
Dim strData() As String = {"Dog", "Cat", "Mouse"}
If networkStream.CanWrite Then
'This is not the proper way. What should I do here?
Dim SentData As Byte()
SentData = Encoding.ASCII.GetBytes(strData)
NetworkStream.Write(SentData, 0, SentData.Length())
End If
そして、これが受信用の私のコードです。
Dim rcvData() As String
If networkStream.CanWrite Then
'Again, I don't think this is the proper way of handling an array of strings.
Dim ByteData(ClientSocket.ReceiveBufferSize) As Byte
NetworkStream.Read(ByteData, 0, CInt(ClientSocket.ReceiveBufferSize))
rcvData = Encoding.ASCII.GetString(ByteData)
End If