in reply to local socket
Here's an example, using IO::Socket:
Start this running, then try connecting from various computers. You'll only be able to connect from the local computer, and only when connecting specifically to 'localhost'. (Exit the server with a kill signal, e.g. Ctrl-C)#!/usr/local/bin/perl -w use strict; use IO::Socket; my $sock = IO::Socket::INET->new(Listen => 1, LocalAddr => 'localhost', LocalPort => 43546, Proto => 'tcp', Reuse => 1, ); my $NL = "\015\012"; while (my $client = $sock->accept()) { print $client "Hello. To close connection, type quit$NL"; while (<$client>) { tr/\015\012//d; print "Client said $_\n"; print $client "You said $_$NL"; last if /^quit/i; } print "Client quit.\n"; print $client "Bye!$NL"; close $client; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: local socket
by Punto (Scribe) on Jun 05, 2001 at 08:47 UTC | |
by Anonymous Monk on Jun 05, 2001 at 19:12 UTC | |
|
Re: Re: local socket
by John M. Dlugosz (Monsignor) on Jun 04, 2001 at 19:27 UTC | |
by chipmunk (Parson) on Jun 04, 2001 at 20:22 UTC | |
by John M. Dlugosz (Monsignor) on Jun 04, 2001 at 23:03 UTC | |
by tye (Sage) on Jun 04, 2001 at 23:17 UTC |