Night Walker
Night Walker

Reputation: 21260

How can I connect to a remote machine via TCP and UDP with Perl?

I have a script that runs on a server and I want it now to send messages to my PC. I want to send TCP or UDP messages to some port.

What is the best way to do this (a tutorial will be great)?

And is there some client program that I can run on my PC that will listen to a local port for the messages?

Upvotes: 2

Views: 607

Answers (5)

brian d foy
brian d foy

Reputation: 132775

Although a bit dated, you want want to find a copy of Network Programming with Perl by Lincoln Stein. Also, look at the Perl modules with Socket in their names.

Upvotes: 1

user80168
user80168

Reputation:

Start with reading of perlipc documentation - it contains examples of simple servers and clients, with a lot of very important addons (like: how to properly daemonize).

Upvotes: 2

Andomar
Andomar

Reputation: 238068

A client can send TCP and UDP messages using a socket, for example:

use IO::Socket;
my $socket = IO::Socket::INET->new(PeerAddr => 'theserver',
    PeerPort => '1234', Proto => 'tcp', Type => SOCK_STREAM);
print $socket "Hello server!";
close($socket);

A server has to listen on a port, and accept messages that arrive on it:

my $socket = new IO::Socket::INET (LocalHost => 'hostname',
    LocalPort => '1234', Proto => 'tcp', Listen => 1, Reuse => 1);
my $incoming = $sock->accept();
while(<$incoming>) {
    print $_;
}
close($incoming);

This is just the tip of the iceberg, but hopefully this will help to get you started.

Upvotes: 8

user181548
user181548

Reputation:

There are a lot of ways to do it. One of the easiest is to have your program email your email address. In Perl, you can use, e.g. Email::Send. Other ways include sockets, or having your program access a web server on your PC. It depends what facilities you want to use. I usually use a ssh command to access other computers across a network.

Upvotes: 0

Peter
Peter

Reputation: 38455

You could use Net Send if your on windows, Write "Net Help Send" for more info in CMD i don't know perl but start CMD Net Send Computer Message

Make sure thet the net send service is running... google it for more info.

Upvotes: 0

Related Questions