Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Client / Server app

by jdgamache (Novice)
on Feb 12, 2001 at 19:40 UTC ( #57900=snippet: print w/replies, xml ) Need Help??
Description: Here is the startup code for a Client server application, it's quite cool!
There is the code for the server and the client: Here is the code for the server you have to change the machine name.
use IO::Socket;
use IO::Select;

my $machine_addr = 'sb002562';
$main_sock = new IO::Socket::INET(LocalAddr=>$machine_addr,

die "Could not connect: $!" unless $main_sock;
print "Starting Server\n";

$readable_handles = new IO::Select();

while (1)
  ($new_readable) = IO::Select->select($readable_handles, undef, undef
+, 0);

  foreach $sock (@$new_readable)
    if ($sock == $main_sock)
      $new_sock = $sock->accept();
      $buf = <$sock>;
      if ($buf)
        print "$buf\n";


print "Terminating Server\n";
close $main_sock;
Here is the code for the Client you have to change the machine name.
use IO::Socket;
use IO::Pipe;
my $machine_addr = 'sb002562';
$sock = new IO::Socket::INET(PeerAddr=>$machine_addr,

die "Could not connect: $!" unless $sock;
$id = shift;

foreach (1 .. 10) {
  print $sock "From $id: Msg $_: How are you?\n";

close ($sock);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://57900]
[tye]: I just daemonized and getlogin() still knew who I had been.
[tye]: perhaps loginuid ? Not that I concede that something not being in /proc means it is not useful.
[Corion]: tye: That's really interesting, but maybe it is because getlogin() returns the name, or the uid, so if that user has been replaced by another user with the same uid in the meantime, that's no problem to the system...
[davido]: or on ubuntu /var/run/utmp
[Corion]: Otherwise, I would imagine that a user with a process still alive would lock that information in memory.
[davido]: so last -f /var/run/utmp on ubuntu provides similar (though more verbose) info
[oiskuu]: glibc getlogin just does ttyname() and falls back on getutline(); it's not security related at all. (reminds me of sendmail and remote finger services of the naive early spam era)
[Corion]: But yes, "who started this process" is interesting information :)
[tye]: no, I really believe that "login user" was added as a fundamental bit of info about each process in order to enhance the usefulness of auditing
[Corion]: Ah - if that information is saved in a file, then you could theoretically spam that file and confuse getlogin(). So, don't use it for authentication :)

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2017-06-23 19:36 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (554 votes). Check out past polls.