daniel_mesquita has asked for the wisdom of the Perl Monks concerning the following question:
Server#! /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";
tks for the help#!/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; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perl chat
by pc88mxer (Vicar) on Apr 24, 2008 at 16:44 UTC | |
| |
|
Re: perl chat
by zentara (Cardinal) on Apr 24, 2008 at 19:01 UTC |