Nate Bross
Contributor
I have this code (posting the whole class for context) I am creating a collection of 'clients' each client has a received data event.
If you look at the Test() sub, these are the values of the variables, and the unexpected results.
First Time Called:
Data() = "Test" (in byte array)
str = nothing
ols = Encoding.ASCII.GetString(Data) = "Test" (this part works)
str = String.Concat(str, ols) = "Test"
Second Time Called:
Data() = "a Second Test" (in byte array)
str = "Test"
ols = Encoding.ASCII.GetString(Data) = "a Second Test" (this part works)
str = String.Concat(str, ols) = "Test"
Third Time Called:
Data() = "a Third Test" (in byte array)
str = "Test"
ols = Encoding.ASCII.GetString(Data) = "a Third Test" (this part works)
str = String.Concat(str, ols) = "Test"
The variable ols has the correct value, but it never gets concatonated to the other string. No matter what I do, the String.Concat NEVER concats the second string to the first one, on any subsequent calling of the method. It ONLY works the first time. Does anyone have any sugestions or ideas to follow?
If you look at the Test() sub, these are the values of the variables, and the unexpected results.
First Time Called:
Data() = "Test" (in byte array)
str = nothing
ols = Encoding.ASCII.GetString(Data) = "Test" (this part works)
str = String.Concat(str, ols) = "Test"
Second Time Called:
Data() = "a Second Test" (in byte array)
str = "Test"
ols = Encoding.ASCII.GetString(Data) = "a Second Test" (this part works)
str = String.Concat(str, ols) = "Test"
Third Time Called:
Data() = "a Third Test" (in byte array)
str = "Test"
ols = Encoding.ASCII.GetString(Data) = "a Third Test" (this part works)
str = String.Concat(str, ols) = "Test"
The variable ols has the correct value, but it never gets concatonated to the other string. No matter what I do, the String.Concat NEVER concats the second string to the first one, on any subsequent calling of the method. It ONLY works the first time. Does anyone have any sugestions or ideas to follow?
Visual Basic:
Public Class Listener
Dim TcpIpListener As TcpListener
Dim ListenThread As Thread
Dim Clients As Connections
Dim str As String
Public Sub New(ByVal IP As IPAddress, ByVal iPort As Integer, ByRef ClientCollection As Connections)
TcpIpListener = New TcpListener(IP, iPort)
Clients = ClientCollection
ListenThread = New Thread(AddressOf Listen)
ListenThread.Start()
End Sub
Sub Listen()
TcpIpListener.Start()
While True
If TcpIpListener.Pending = True Then
Dim tcpInConn As Communication.Client
tcpInConn = New Communication.Client(TcpIpListener.AcceptTcpClient())
Clients.Add(tcpInConn)
AddHandler tcpInConn.DataReceived, AddressOf Test
End If
Application.DoEvents()
End While
TcpIpListener.Stop()
End Sub
Private Sub Test(ByVal sender As Object, ByVal Data() As Byte)
Dim ols As String = ""
ols = Encoding.ASCII.GetString(Data)
str = String.Concat(str, ols)
End Sub
Public ReadOnly Property S()
Get
Return str
End Get
End Property
End Class