Joseph C. Bautista <> wrote:
> Hi All,
>
> I am trying to write a client SOCKET programming and I want to
> capture the response from Server. The scenario is if I tried the
> username and password, which you can see below, the server response
> with ACK and timestamp.
>
> I want to capture the timestamp, could somebody tell me how can I do
> that?
>
> $ telnet 102.120.64.101 3010
> Trying...
> Connected to 102.120.64.101
> Escape character is '^]'.
> kewl,blue27; <-- Username and password
> ACKNOWLEDGE,STAMP=2006100510374109; <<-- Response from Server
>
> And here is my code:
>
> my ( $file ) = @_;
> my $sock = new IO::Socket::INET ( PeerAddr => '102.120.64.101',
> PeerPort => '3010', Proto => 'tcp' ); $sock->autoflush(1); die
> "Could not create socket: $!\n" unless $sock; my $line; open FOUT,
> ">>message.log"; open FILE, "$file"; print $sock 'kewl,blue27;';
> $result=<$sock>; # << seems not working :( print "The response
is :
> $result"; print STDOUT "The response is : $result\n"; close FILE;
> close FOUT; close($sock);
>
> Could somebody tell me what is wrong with my code?
Some of the things that your code is doing wrong are:
It is badly formatted making it hard to read (but that may well be my
Outlook rather than whatever you used).
It doesn't start with "use strict; use warnings;".
You dereference $sock before checking whether it is defined.
You don't check the results of opening 2 files.
You don't appear to be using those files.
You don't check the result of closing an output file.
Useless quoting ("$file") in open. (It is often recommended these days
to use the 3 arg form of open with lexically scoped file handles, e.g.
open my $fd, "<", $file or die ...)
Finally one that may be related to your stated problem. When you used
telnet, did you hit the enter key after typing the username and
password? If so you will need to do the same in your script, i.e.
something like \n or possibly \r\n.
HTH
--
Brian Raven
=================================
Atos Euronext Market Solutions Disclaimer
=================================
The information contained in this e-mail is confidential and solely for the
intended addressee(s). Unauthorised reproduction, disclosure, modification,
and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediately
and delete it from your system. The views expressed in this message do not
necessarily reflect those of Atos Euronext Market Solutions.
L'information contenue dans cet e-mail est confidentielle et uniquement
destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee.
Toute copie, publication ou diffusion de cet email est interdite. Si cet e-mail
vous parvient par erreur, nous vous prions de bien vouloir prevenir
l'expediteur immediatement et d'effacer le e-mail et annexes jointes de votre
systeme. Le contenu de ce message electronique ne represente pas necessairement
la position ou le point de vue d'Atos Euronext Market Solutions.
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs