Code Comments
Programming Forum and web based access to our favorite programming groups.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);
Post Follow-up to this messageJonas 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 mcse.ms - Unlimited-Uncensored-Secure Usenet News==- --- http://www.mcse.ms The #1 Newsgroup Service in the World! >100,000 New sgroups ---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Post Follow-up to this message
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.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.