question about socket and scalar.

question about socket and scalar.

am 02.06.2007 23:27:10 von none

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";
}

Re: question about socket and scalar.

am 03.06.2007 00:18:28 von Bob Walton

_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.
>
> Mario.
....
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl

Re: question about socket and scalar.

am 03.06.2007 00:18:28 von Bob Walton

_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.
>
> Mario.
....
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl

Re: question about socket and scalar.

am 04.06.2007 18:27:24 von Jim Gibson

In article , _mario.lat
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=)) {
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

Re: question about socket and scalar.

am 04.06.2007 18:27:24 von Jim Gibson

In article , _mario.lat
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=)) {
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

Re: question about socket and scalar.

am 05.06.2007 01:26:16 von Jim Gibson

In article <040620070927246688%jgibson@mail.arc.nasa.gov>, Jim Gibson
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

Re: question about socket and scalar.

am 05.06.2007 01:26:16 von Jim Gibson

In article <040620070927246688%jgibson@mail.arc.nasa.gov>, Jim Gibson
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

Re: question about socket and scalar.

am 05.06.2007 10:00:08 von Joe Smith

_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

Re: question about socket and scalar.

am 05.06.2007 10:00:08 von Joe Smith

_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