Not exactly sure about that I am still fairly new with working with collections and am working off some code examples. Here is my code so far i have cut out most of the irrelivant stuff :
Public Class clsClientObj
Public Sub New(ByVal ParentCollectionRef As clsClientCol)
Col = ParentCollectionRef
End Sub
'accepts the incomming connection, opens the stream and starts the dataarrival thread
Public Sub Accept(ByVal Connection As System.Net.Sockets.TcpListener)
'accept the incomming connection
tcpClient = Connection.AcceptSocket
'open the stream to the socket so we can sent data back and forth
Stream = New NetworkStream(tcpClient)
StreamWriter = New BinaryWriter(Stream)
StreamReader = New BinaryReader(Stream)
'start the dataarrival thread so it always reads from the stream when data comes in from the
'client
DataArrivalThread = New Thread(AddressOf DataArrival)
DataArrivalThread.Priority = ThreadPriority.Lowest
DataArrivalThread.Start()
End Sub
...........................
Public Class clsClientCol
Inherits System.Collections.CollectionBase
Public Overridable Function Add(ByVal value As clsClientObj) As Integer
MyBase.List.Add(value)
End Function
Public Overridable Function Remove(ByVal value As clsClientObj) As Integer
MyBase.List.Remove(value)
End Function
Default Public Overridable Property Item(ByVal index As Integer) As clsClientObj
Get
Return DirectCast(MyBase.List.Item(index), clsClientObj)
End Get
Set(ByVal value As clsClientObj)
MyBase.List.Item(index) = value
End Set
End Property
End Class
Public Class Form1
Inherits System.Windows.Forms.Form
Private Client As New clsClientCol()
Private ClientObj As New clsClientObj(Client)
Private Sub Listener_ClientConnecting(ByVal Connection As System.Net.Sockets.TcpListener) Handles Listener.ClientConnecting
ClientObj.Accept(Connection) 'accept the incomming connection
Client.Add(ClientObj) 'add the client that just connected to the collection
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Listener.Start_Server() 'start the multithreaded listener
End Sub
Private Sub btnMsg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMsg.Click
MsgBox(Client.Count)
End Sub
End Class