I am writing a chat/instant messaging server.

Normal chat clients connect to the server to chat, so for them I need to create an object to sustain their state, info, etc. The problem is when I try to connect two servers together, so that one server connects to the other and they can pass chat messages across.

Scenario: server1, server2

The admins of server1 and server2 want to join their chat servers, and make it a chat network. Both servers are listening for connections from chat clients. server1 makes a socket connection to server2. This socket will be used to pass chat messages from one server to the other. In this case server1 has to listen on its server socket and the other socket it has created, whereas server2 is only listening on its server socket.

In server1's scenario, I add the connection to the other server to select from inside a Server object.

OK, I know now how to figure out where the data is coming from (server1's server socket or server1's connection socket to server2).

I have this code:

my $select = IO::Select->new($listen); while(1) { my($r,$w) = IO::Select->select($select, $select, undef, 0); my $socket; for $socket (@$r) { ... } for $socket (@$w) { ... }
AFAIK, the above code should block until it comes across a socket that is either readable or writeable.

In reply to Re: Re: select() on a client and server socket by amir
in thread select() on a client and server socket by amir

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.