in reply to chat between client and server

Writing threaded bi-directional socket apps is not going to be as simple as you write in your code. With moritz's fix, I can send from client to server, but no luck sending from server to client.... it silently crashes. I would also watch for memory gains if you do get those bugs worked out, see multithreaded tcp listener with IO::Socket and threaded TCP server problem and ChatServer

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Replies are listed 'Best First'.
Re^2: chat between client and server
by wavenator (Novice) on Oct 11, 2007 at 16:41 UTC
    i've already read these topics and still hasnt find the answer
      Its a complex interaction to have multi-threaded client talking in a bidirectional manner to a mutithreaded server. To be honest, I've only seen 1 example of a multi-threaded server that worked, and that was with a forking client. You are jumping into very deep water, and you expect some simple looking scripts to have working complex functionality. I would suggest you study how the forking chat server-clients work first, before complicating it with threads.

      My first guess is that you need some IO::Select stuff in the threads.

      My second guess is that you create your threads after you create your IO::Socket object, so both threads get their own copy of the object. That probably raises havoc. I would try to create the threads before you make the IO::Socket, then share the socket filehandle with the threads thru a shared variable. Then you can have some IO::Select loop in the threads to detect when they are in a recv or send mode. You can't read when the socket is in send mode, and vice-versa.....thats called blocking.

      I don't want to discourage you from trying to figure this all out, but no one has done it before, and its for a reason. That reason is it involves alot of complex juggling of the socket filehandle, which you just sort of ignore with your simple code.


      I'm not really a human, but I play one on earth. Cogito ergo sum a bum