For Programmers: Free Programming Magazines  


Home > Archive > PERL Modules > April 2005 > Information transfer over the internet









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Information transfer over the internet
Jonas Nilsson

2005-04-07, 3:56 am

Hello
I would like to transfer some information between two computers with
internet connection. One computer should act as a server and the other as a
client. I really don't know much about sockets, ports or protocols.

I played around some with the code below but i reallt don't know what I am
doing. The module Net::Server::NonBlocking2 is the same as
Net::Server::NonBlocking, but I removed some error checking due to problems
with unimplemented perl funcions on my PC. This actually givs some
information to a browser when I type http://127.0.0.1:10000. This however
isn't working properly.I actually have to close the client to get any
response at all. There must be some modules that easily and nicely can do
something like the quasicode below.

Please assist me.
/jN

_CODE_
use Net::Server::NonBlocking2;
$|=1;

$obj=Net::Server::NonBlocking2->new({"pidfile" => "tmppid.pid"});
$obj->add({
server_name => 'tic tac toe',
local_port => 10000,
timeout => 60,
delimiter => "\n",
on_connected => \&ttt_connected,
on_disconnected => \&ttt_disconnected,
on_recv_msg => \&ttt_message,
});
our $cnt="000";
$obj->start;
sub ttt_connected {
my $self=shift;
my $client=shift;
print "connect:\t$client\n";
}
sub ttt_disconnected {
my $self=shift;
my $client=shift;
print "disconnect:\t$client\n";
}
sub ttt_message {
my $self=shift;
my $client=shift;
my $message=shift;
print "(mess ",$cnt++,")\n";
print "$message\n";
print $client "dfgdg: message<BR>testmessage<BR>";
$client->close;
}

_QUASICODE_

server:
while (1) {
if (&new_message) {
my $input=&message;
my $output=&parse($input);
&send_message($output);
} else {
sleep(5);
}
}

client:
my $request="Give me checksum of C:/Tmp/test.txt";
my $answer=&send_request($request,"mycomp.mynet.com") or "Die no answer!";
&handle($answer);


Bob Walton

2005-04-07, 3:56 am

Jonas Nilsson wrote:

> Hello
> I would like to transfer some information between two computers with
> internet connection. One computer should act as a server and the other as a
> client. I really don't know much about sockets, ports or protocols.


Check out:

perldoc perlipc

at a command prompt, particulary the section titled "Internet TCP
Clients and Servers". There is example code there which should
get you on your way.

....

--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Brian McCauley

2005-04-07, 3:56 am



Jonas Nilsson wrote:

>
> comp.lang.perl.misc:
>
>
>
>
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:d2gcsv$iul$1@mamenchi.zrz.TU-Berlin.DE...
>
>
>
> Actually no. I just try to do some learning by playing around... Not very
> successfuly however, since the issue is a bit more complex than I realized.
>
> Actually I need something very simple that can send strings/binaries over
> the internet between a perl-client and a perl-server. Re-posting the
> quasicode from the initial message might clear up my intentions:
>
> _QUASICODE_
>
> server:
> while (1) {
> if (&new_message) {
> my $input=&message;
> my $output=&parse($input);
> &send_message($output);
> } else {
> sleep(5);
> }
> }
>
> client:
> my $request="Give me checksum of C:/Tmp/test.txt";
> my $answer=&send_request($request,"mycomp.mynet.com") or "Die no answer!";
> &handle($answer);


I suggest you look at the section that deals with sockets in any Perl
tutorial.

In the standard Perl documentation there's some socket examples in perlipc.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com