CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Sockets

 



shockwire
newbie

Jul 30, 2001, 3:44 PM

Post #1 of 2 (522 views)
Sockets Can't Post

I'm trying to make a perl script that asks for remote host, remote port and connects. This is what I have so far, but I'm not sure if there is any way I can view things from the socket, while being able to type into the socket:

Code
#!/usr/bin/perl


Code
use Socket;


Code
print "Remote Host: "; 
$host = <STDIN>;
$host =~ s/\n//gi;
print "Remote Port: ";
$port = <STDIN>;
$port =~ s/\n//gi;


Code
print "\nCreating Socket...\t"; 
socket(SH, PF_INET, SOCK_STREAM, getprotobyname('tcp')) || die $!;
print "OK.\nCreating Destination...\t";
$dest = sockaddr_in($port, inet_aton('$host'));
print "OK.\nConnecting to server...\t";
connect(SH, $dest) || die $!;
print "OK.\n\n";


Code
print "Selecting Socket Handle, Flushing, Selecting STDOUT...\t"; 
select(SH); $| = 1; select(STDOUT);


Code
# This is where I want the sending/receiving to being.. 
# But I cannot figure out a way to do this. I can't even figure out how to receive input from the remote host.


Code
print "\n\nClosing Connection.\n\n"; 
close(SH);

Can anyone help me...?



mhx
Enthusiast / Moderator

Jul 30, 2001, 9:59 PM

Post #2 of 2 (512 views)
Re: Sockets [In reply to] Can't Post

Have a look a the IO::Select manpage, it should give you an idea how you can solve this problem.

-- Marcus


Code
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= 
($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives