shadowoflinux has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl # use strict; use warnings; use IO::Socket; my $sock = new IO::Socket::INET ( PeerAddr => 'dan', PeerPort => '7070', Proto => 'tcp', ); die "Could not create socket: $!\n" unless $sock; print "What would you like to say: "; my $msg = <STDIN>; print $sock "$msg\n"; close $sock;
recieve.p code
#!/usr/bin/perl # use strict; use warnings; use IO::Socket; my $sock = new IO::Socket::INET ( LocalHost => 'dan', LocalPort => '7070', Proto => 'tcp', Listen => 1, Reuse => 1, ); die "Could not create socket: $!\n" unless $sock; my $new_sock = $sock->accept(); while(<$new_sock>) { print $_; } close $sock;
how could i modify those scripts so that a) they dont close after 1 message and b) so that the same script can be used to send and recieve?
thanks
EDIT: is there a way of setting up the scripts so they can send and recieve at the same time, without using a server, so they connect directly to each other, almost like a 2-way radio?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl Sockets Problem
by zentara (Cardinal) on Jun 01, 2006 at 16:10 UTC | |
|
Re: Perl Sockets Problem
by ikegami (Patriarch) on Jun 01, 2006 at 17:53 UTC | |
|
Re: Perl Sockets Problem
by dsheroh (Monsignor) on Jun 01, 2006 at 16:11 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |