here is the thing, first of all i don't speak very well english, so sorry about the errors.. I need to create something in perl, Create one server and one or two clients, using sockets, to trade messages betwin the clients, in one LAN for example, I already done something using sockets and there is the code, is a calculator but has no interaction with the user, and i need that to the chat.. Client:
#! /usr/bin/perl -w # client1.pl - a simple client use strict; use Socket; my $host = shift || 'localhost'; my $port = shift || 7890; my $proto = getprotobyname('tcp'); my $line; my $end = 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 "Client connected \n"; while ($end == 0) { $line = <SOCKET>; print "Data received from server: \n"; chomp ($line); print $line,"\n"; if ($line eq "OK") { print "->OK received. Will send data\n"; print SOCKET "30/2\n"; print "Data sent\n"; } elsif ($line =~ /[0-9]+/) { print "Resultado: $line"; $end = 1; } else { print "Data unrecognized...\n"; #sleep(1); $end = 1; } } 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 started on port $port \n"; my $client_addr; my $calc=0; my @data; while ($client_addr = accept(CLIENT, SERVER)) { my $old_fh = select(CLIENT); $| = 1; select($old_fh); print "New connection established.\n"; print "Requesting data...\n"; print CLIENT "OK\n"; print "OK sent!\n"; while ($calc == 0) { print "reading...\n"; $calc = <CLIENT>; } print "Data: \n"; print $calc; @data = split(/(\+|\*|\/|\-)/,$calc); if ($data[1] eq "+") { print CLIENT $data[0]+$data[2]; } if ($data[1] eq "-") { print CLIENT $data[0]-$data[2]; } if ($data[1] eq "*") { print CLIENT $data[0]*$data[2]; } if ($data[1] eq "/") { print CLIENT $data[0]/$data[2]; } close CLIENT; print "--END--"; exit; }
based on that code some hellp me to create, or create the code to use one server and one or more clients, to trade messages betwin them, pls i really need your help. Urgent

In reply to Perl Chat or privat messenger 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.