client/ server

S

spleen

Hiya,

Basically at the moment Im planning on using a python script to send a
string of text to a website, I was woundering in perl, using the cgi-bin how
I can accept this connection and take the text string and add it to a file
(.txt)

cheers

greg
 
B

Brian McCauley

spleen said:
Basically at the moment Im planning on using a python script to send a
string of text to a website, I was woundering in perl, using the cgi-bin how
I can accept this connection and take the text string and add it to a file
(.txt)

Basically, you should either learn en enough Perl write a script yourself or hire
someone who knows enough Perl to write it for you.

Examples and tutorials of writing trivial CGI scipts in Perl can be
found all over the place.

If you have problems feel free to come here for help.

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
S

spleen

Yea sorry my first post wasnt very clear, Ive sorted the perl - I have a
server that takes the text string and puts it into a text file.

all I was woundering how to do was to how to do this on a free hosting
service, I cant seem to get it working on www.spaceports.com

sorry for my misinformed post to start with, my code is posted below.
although I dont think itll help anyone answer me becuase its more the
application of it that im confused by

cheers

gre

#!/usr/local/bin/perl

use IO::Socket;

$file = "/home2/pp10aagg/public_html/sms.txt";
open (FILE, >>$file) or die "cannot open $file: $!";
my $listening_socket =
IO::Socket::INET->new(Proto => 'tcp',
LocalPort => 2323,
Listen => 1,
Reuse => 1) or die $!;

$socket = $listening_socket->accept;
$socket->recv($line, 80);
print FILE "$line";
$socket->close;
close (FILE);


Brian McCauley said:
spleen said:
Basically at the moment Im planning on using a python script to send a
string of text to a website, I was woundering in perl, using the cgi-bin how
I can accept this connection and take the text string and add it to a file
(.txt)

Basically, you should either learn en enough Perl write a script yourself or hire
someone who knows enough Perl to write it for you.

Examples and tutorials of writing trivial CGI scipts in Perl can be
found all over the place.

If you have problems feel free to come here for help.

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
N

nobull

"spleen" <[email protected]> spits TOFU in my face:

[ Don't do that, it is rude ]
Yea sorry my first post wasnt very clear, Ive sorted the perl - I have a
server that takes the text string and puts it into a text file.
all I was woundering how to do was to how to do this on a free hosting
service, I cant seem to get it working on www.spaceports.com

Asking how to install arbritrary server software on a hosting service
is best directed to their technical support. In general don't expect
a free service to allow you to do this.

If they've not taken any technical measures to prevent you opening a
listening socket then you could make a CGI script that forks a daemon
process (see FAQ "How do I fork a daemon process?") but you'd probably
get kicked off as soon as the admins notice you doing this.
sorry for my misinformed post to start with, my code is posted below.
although I dont think itll help anyone answer me becuase its more the
application of it that im confused by

#!/usr/local/bin/perl

[ no warnings, no strict ]

Do not climb without ropes until you are an experienced climber. You
will not endear yourself to the experienced climbers if you take the
attitude: "I'm new, I can't figure out all these ropes, they just get
in the way, I'll learn them later". Yes the ropes will slow you down
at first, but the first time you fall you will loose much more time
than the time it would have taken you to figure out the ropes.
use IO::Socket;

$file = "/home2/pp10aagg/public_html/sms.txt";
open (FILE, >>$file) or die "cannot open $file: $!";

That is a syntax error - please cut/paste your code, do not retype.
my $listening_socket =
IO::Socket::INET->new(Proto => 'tcp',
LocalPort => 2323,
Listen => 1,
Reuse => 1) or die $!;

$socket = $listening_socket->accept;

You probably want to be doing that inside a loop.
$socket->recv($line, 80);

Do not use low-level system calls recv() or sysread() on a stream
based protocol (e.g. TCP) unless you know what you are doing (and you
are prepared to handle short returns). For short messages you'll
often get away with it - but sooner or later you'll get burned.

Decide how the end of the message is to be indicated and use a
mechanism that reads everything until that condition is met.

This, of course, has nothing to do with Perl. It applies equally to
all programming languages in all environments using even vaguely
POSIX-like file descriptors.
print FILE "$line";

See FAQ: What's wrong with always quoting "$vars"?
$socket->close;

If your variables are properly scoped you very rarely need to
explicitly close sockets and suchlike.
 
B

Bob Walton

spleen wrote:

....

Basically at the moment Im planning on using a python script to send a
string of text to a website, I was woundering in perl, using the cgi-bin how
I can accept this connection and take the text string and add it to a file
(.txt)


Hmmmm...well, if Python has something along the lines of Perl's

use LWP::Simple;

and your string isn't too long, you could embed your text string
(properly quoted) into a URL as a parameter value and use a simple CGI
script to grab the string and append it to your file. Something like:

#!/usr/bin/perl
use warnings;
use strict;
use CGI qw:)standard);
use CGI::Carp qw(fatalsToBrowser);
print header,start_html;
if(param('string')){
open OUT,'>>file.txt' or die "Oops, couldn't open file.txt for
append, $!";
print OUT param('string');
close OUT;
print "Successful.";
}
else{
print "Bad URL, no string parameter";
}
print end_html;

[Tested with:

perl filename.pl string=foo

]
....

....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top