|
|
 |
 |
 |
 |
Perl Programming Language
|
 |
 |
 |
 |
 |
 |
 |
 |
question about socket and scalar.
Hammol, I see an example about IPv6... I'm a newby and I like to ask you someting about code: -What can I put in the code(see following code) for writing what the server says? -What "scalar(@res)" do? Thank you in advance, Mario. use Socket; use Socket6; @res = getaddrinfo('hishost.com', 'daytime', AF_UNSPEC, SOCK_STREAM); $family = -1; while (scalar(@res) >= 5) { ($family, $socktype, $proto, $saddr, $canonname, @res) = @res; ($host, $port) = getnameinfo($saddr, NI_NUMERICHOST | NI_NUMERICSERV); print STDERR "Trying to connect to $host port port $port...\n"; socket(Socket_Handle, $family, $socktype, $proto) || next; connect(Socket_Handle, $saddr) && last; -----> WHAT CAN I PUT HERE TO PRINT WHAT SERVER SAYS? close(Socket_Handle); $family = -1; } if ($family != -1) { print STDERR "connected to $host port port $port\n"; } else { die "connect attempt failed\n"; }
_mario.lat wrote: > ... > I'm a newby and I like to ask you someting about code: ... > -What "scalar(@res)" do?
The function scalar() returns its argument evaluated in scalar context. In the case of an array as the argument, it returns the number of elements in the array. Please type: perldoc -f scalar at a command prompt on your computer, which will answer this question much more quickly and thoroughly than asking a newsgroup. ... -- Bob Walton Email: http://bwalton.com/cgi-bin/emailbob.pl
In article <pan.2007.06.02.21.27.10.539@libero.it>, _mario.lat
<n @libero.it> wrote: > Hammol, > I see an example about IPv6... > I'm a newby and I like to ask you someting about code: > -What can I put in the code(see following code) for writing what the > server says? > -What "scalar(@res)" do? > Thank you in advance, > Mario. > use Socket; > use Socket6; > @res = getaddrinfo('hishost.com', 'daytime', AF_UNSPEC, SOCK_STREAM); > $family = -1; > while (scalar(@res) >= 5) { > ($family, $socktype, $proto, $saddr, $canonname, @res) = @res; > ($host, $port) = getnameinfo($saddr, NI_NUMERICHOST | NI_NUMERICSERV); > print STDERR "Trying to connect to $host port port $port...\n"; > socket(Socket_Handle, $family, $socktype, $proto) || next; > connect(Socket_Handle, $saddr) && last; > -----> WHAT CAN I PUT HERE TO PRINT WHAT SERVER SAYS?
If what "server says" is text terminated by new-lines: while( defined($line=<Socket_Handle>)) { print $line; } See 'perldoc ipc' and search for 'Internet TCP Clients and Servers' > close(Socket_Handle); > $family = -1; > } > if ($family != -1) { > print STDERR "connected to $host port port $port\n"; > } else { > die "connect attempt failed\n"; > }
Posted Via Usenet.com Premium Usenet Newsgroup Services ---------------------------------------------------------- ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY ** ---------------------------------------------------------- http://www.usenet.com
In article <040620070927246688%jgib@mail.arc.nasa.gov>, Jim Gibson <jgib @mail.arc.nasa.gov> wrote: > See 'perldoc ipc' and search for 'Internet TCP Clients and Servers' Sorry, but that is 'perldoc perlipc'. -- Jim Gibson Posted Via Usenet.com Premium Usenet Newsgroup Services ---------------------------------------------------------- ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY ** ---------------------------------------------------------- http://www.usenet.com
_mario.lat wrote: > socket(Socket_Handle, $family, $socktype, $proto) || next; > connect(Socket_Handle, $saddr) && last; > -----> WHAT CAN I PUT HERE TO PRINT WHAT SERVER SAYS?
It depends on whether the server is sending ordinary lines of text or binary data. For binary, you'll need to worry about is the end-of-field, end-of-record/packet and end-of-stream indicators, as well as the expected maximum size of a packet. -Joe
|
 |
 |
 |
 |
|