Hello all, this is my first post here, so I hope I don't screw it up :) I've been looking at the Question/Answer stuff on sockets, and I'm haven't found anything addressing my problem.
Basically, I'm trying to send a string over a socket, and not necessarily to a webserver, but I'll use that in my example, and check the return value for a certain string. I can do the check no problem, its actually getting the stuff to check that has been a problem. I use IO::Socket to set up all the socket stuff. I can 1) send the string over the socket, and 2) output the return stuff. However, after all the stuff returns, it just leaves me hanging . . .the rest of the code doesn't execute. From the commmand line (linux), if I do a 'telnet www.espn.com 80' and then 'GET /index.html HTTP/1.0', it'll return the html stuff, then exit out. However, I think whats happening in my program is that the remote host is closing its connection, but my side is staying open, still waiting for more input. Considering I'll be looking at various things like webservers, email servers, etc. I can't set a had value, like look at 10 lines, then exit. I'm not sure how to check if their connection has been closed. Sorry I'm being so wordy, but thanks ahead of time.
use IO::Socket
$ip = "204.202.136.31"; ## www.espn.com for fun :)
$port = "80";
$socket = IO::Socket::INET->new(PeerAddr => $ip,
PeerPort => $port,
Proto => "tcp",
Type => SOCK_STREAM) or die "@";
print $socket "GET /index.html HTTP/1.0\n\r\n\r";
while (<$socket>) {
print $_;
}
close ($socket);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.