#!/usr/bin/env perl use strict; use warnings; use IO::Socket::INET qw(CRLF); use IO::Select; my $socket = IO::Socket::INET->new( Listen => 5, LocalPort => 7777, Reuse => 1, ) or die $!; my $reader = IO::Select->new($socket); my @clients; while (1) { for my $ready ($reader->can_read()) { if ($ready == $socket) { my $client = $socket->accept(); $reader->add($client); push @clients,$client; } else { my $buffer; sysread($ready,$buffer,1024); for my $client (@clients) { if ($client != $ready) { # Dont echo to client whose chatt +ing syswrite($client,$buffer); } } } } }
So I came up with this, it is pretty much all based on the same reference that karl mentioned to Network Programming by Stein. If you already have a group chat then it should be easy to adapt. instead of pushing your clients to an array as done here it would go into maybe a two dimensional array where each element is a client that talks to the other element and no one else. Or a hash with the key as the login name. You did not say who you want to talk to who. Maybe they enter a password and then that is the key to the hash that contains some structure that leads to the socket you want to write to. If that makes sense.

In reply to Re: Creating an online chat in perl by trippledubs
in thread Creating an online chat in perl by Muskovitz

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.