views:

38

answers:

2

Hi all (Using vb 2008 express.)

I am trying to create a server to send clients text on request. I am using a tcp listener to accept clients then send each client to a thread in a threadpool which deals with each client's request then closes the client connection. It seems to work fine but I would like to know how it works. Using the listen loop below I cant help feeling I should be sending some values to the threaded sub. How does it know which client each thread is dealing with?

Sub ListenLoop()

    Looop:

    Client = Server.AcceptTcpClient

    ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf ClientThread))

    GoTo Looop

End Sub
A: 

It doesn't unless you supply a state object to track which user it is.

Check out MSDN's article on Non-blocking TCP Server:

http://msdn.microsoft.com/en-us/library/fx6588te.aspx

Crowe T. Robot
A: 

Hey folks

Thanks for the quick replies. I was brought up on Qbasic(try not to laugh), I am struggling with VB. NOBUGZ could you give me an example of where you put the overload and how to pass the reference. I think that should be enough information for me to conquer this project. With the exeption of Delegates(brrrrrrrrr).

Thanks in advance this is a great site.

Guy