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

In reply to Re^3: chat between client and server by zentara
in thread chat between client and server by wavenator

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.