in reply to Socket client thread design problem

Try this: Simple threaded chat server.

I think your problem is that you don't differentiate a new connection, from an existing connection. The code shows how it's done, and those scripts are pretty close to the way C would do it.

You do the initial accept with the main thread, then let the threads handle the connection.


I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh
  • Comment on Re: Socket client thread design problem

Replies are listed 'Best First'.
Re^2: Socket client thread design problem
by photron (Novice) on Mar 21, 2014 at 10:34 UTC

    Thanks for the hint. The example shows how to share sockets between threads based on their fileno. I figured this out already and got the Perl code working on Linux with this.

    But on Windows I still ran into problems with this socket sharing and threads due to the problem of threads->create() blocking if a socket is on a locked state. I tried to workaround this and reached like the third layer of workaround code and it's getting worse each layer. That's why I've asked for general design advise.

        This just seems to switch the socket between blocking and non-blocking mode. This can also be done with the Blocking parameter of the IO::Socket::INET. This blocking is not the problem. I actually want my socket blocking like this.