in reply to sharing variables with threads

Even if you could share sockets like that (I don't think you can), every client that connected would replace the $client variable, you can't have more than one client connection referred to by the same variable.


We're not surrounded, we're in a target-rich environment!

Replies are listed 'Best First'.
Re: Re: sharing variables with threads
by Anonymous Monk on Mar 13, 2003 at 01:53 UTC
    would it work if i shared the $line variable, so that everyone would see what everyone is typing?

      No, you are not going to be able to do it the way you are attempting, you will have to keep a list of client connections, and every time you get a line from one client, go through the list and send it to every other client. This would actually work better without threads, using a server that sets all the clients to be non-blocking.


      We're not surrounded, we're in a target-rich environment!
        i was thinking of doing it that way, but i didnt exactly know what i would be grabbing, i figured it would just be throwing the $client variable into an array each time a new connection was made, but when i tried it it didn't work.