Por lo que nos mencionó, los códigos hacen la función de socket en cliente y servidor...
--cliente
Using perl Syntax Highlighting
- #!/usr/bin/perl -w
- # client.pl
- #----------------
- use strict;
- use Socket;
- # initialize host and port
- my $host = shift or `hostname`; # esto no sirve de nada!
- my $port = shift or 7890;
- my $server = "192.168.10.58";
- # create the socket, connect to the port
- socket( SOCKET, AF_INET, SOCK_STREAM, getprotobyname('tcp') )
- or die "Can't create a socket $!\n";
- my $sin = sockaddr_in( $port, inet_aton( $server ) );
- if ( connect ( SOCKET, $sin ) ) {
- while ( my $line = <SOCKET> ) {
- print "$line\n";
- }
- }
- else { die "Can't connect to $server : $!\n"; }
- shutdown( SOCKET, 2 ) or die "close: $!";
Coloreado en 0.006 segundos, usando GeSHi 1.0.8.4
--servidor
Using perl Syntax Highlighting
- #!/usr/bin/perl -w
- use strict;
- use Socket;
- # use port 7890 as default
- my $port = shift or 7890;
- my $proto = getprotobyname('tcp');
- # create a socket, make it reusable
- socket(SOCKET, PF_INET, SOCK_STREAM, $proto)
- or die "Can't open socket $!\n";
- setsockopt(SOCKET, SOL_SOCKET, SO_REUSEADDR, 1)
- or die "Can't set socket option to SO_REUSEADDR $!\n";
- my $paddr = sockaddr_in($port, INADDR_ANY);
- # bind to a port, then listen
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4