the next code connect one server and one client, the connection works and the client already send messages to server. Now i need to replicate the messages to other clients conneced. if anyone correct the code for me... i tks a lot. Client.
#! /usr/bin/perl -w # client0.pl use strict; use Socket; my $host = shift || 'localhost'; my $port = shift || 7890; my $proto = getprotobyname('tcp'); my $line; my $connection = "0"; my $iaddr = inet_aton($host); my $paddr = sockaddr_in($port, $iaddr); socket(SOCKET, PF_INET, SOCK_STREAM, $proto) or die "socket: $!"; my $old_fh = select(SOCKET); $| = 1; select($old_fh); connect(SOCKET, $paddr) or die "connect: $!"; print "Cliente Conectado \n"; while ($connection == 0) { $line = <SOCKET>; chomp ($line); if ($line eq "OK") { my $texto; $texto=<STDIN>; print SOCKET "$texto\n"; print "Passo a citar:\n $texto \n"; print SOCKET "OK\n"; } } close SOCKET or die "close: $!"; print "\n --Client has disconnected-- \n";
Server
#!/usr/bin/perl -w # server0.pl use strict; use Socket; my $port = shift || 7890; my $proto = getprotobyname('tcp'); socket( SERVER, PF_INET, SOCK_STREAM, $proto ) or die "socket: $!"; setsockopt( SERVER, SOL_SOCKET, SO_REUSEADDR, 1 ) or die "setsock: $!" +; my $paddr = sockaddr_in( $port, INADDR_ANY ); bind( SERVER, $paddr ) or die "bind: $!"; listen( SERVER, SOMAXCONN ) or die "listen: $!"; print "SERVER Inicializado na porta $port\n"; my $client_addr; my $connection="0"; my $line; while ( $client_addr = accept( CLIENT, SERVER ) ) { my ( $client_port, $client_ip ) = sockaddr_in($client_addr); my $client_ipnum = inet_ntoa($client_ip); my $client_host = gethostbyaddr( $client_ip, AF_INET ); print "Nova coneccao establecida:\n"; print "Conecção do Cliente $client_host", " [$client_ipnum]\n"; my $old_fh = select(CLIENT); $| = 1; select($old_fh); print CLIENT "OK\n"; while ($connection eq "0") { $line = <CLIENT>; print $line; print CLIENT $line; } }
tks for the help

In reply to perl chat by daniel_mesquita

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.