views:

149

answers:

5

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?

A: 

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.

Kinopiko
I am newbie for perl , and we dont have smtp server on that server .
Night Walker
It isn't very clear what you want to do, so I can't give a clear answer.
Kinopiko
I want to send tcp or udp massages to some port .
Night Walker
What have you tried so far?
Kinopiko
A: 

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.

Petoj
Net Send is blocked on our company network
Night Walker
And on sp3 the default is blocked
Night Walker
Was worth a shot :P
Petoj
+8  A: 

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.

Andomar
Do you know some port sniffer that can listen to my port ?nNot heavy things like wireshark ...
Night Walker
Port sniffers display network traffic, but they don't actually listen. There's a utility called netcat that can listen, for example `nc -l -p 1234` http://www.catonmat.net/blog/unix-utilities-netcat/
Andomar
+2  A: 

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).

depesz
+1  A: 

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.

brian d foy