TcpListener.AcceptTcpClient / MORE THAN ONE

Drstein99

Well-known member
Joined
Sep 26, 2003
Messages
283
Location
Audubon, Nj
When i am running a thread, and i do

dim temptcp as tcpclient

start loop
If listener.Pending Then

Dim tcpTemp As TcpClient = listener.AcceptTcpClient

addToHashTable(tcptemp)

end if

end loop

and it loops through the thread constantly accepting clients, do I have to NEW a NEW tcpclient or clone the client that is returned from the ACCEPTTCPCLIENT call?
 
neither,
pass tcpTemp to an object and create the networkstream from the tcp client.
example, i wrote a small text based poker program and created a new player each time a player connected through acceptTCPClient and passed the client to the constructor of the player, used client.GetStream and communicated through binarywriter(stream) and binaryreader(stream)

New Player(c as tcpClient)
client = c


Dim stream As NetworkStream = client.GetStream
Dim w As BinaryWriter = New BinaryWriter(stream)
Dim r As BinaryReader = New BinaryReader(stream)
 
Thanks for the advice. I decided to DROP the tcpclient altogether, Im now using sockets to attach. When successful, I pass the network stream to the object, which seems to be all that I need.
 
Back
Top