From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alejandro
Santillan
Sent: 24 October 2006 16:49
To: [email protected]
Subject: help with sockets
> I need to connect to a TCP server that uses a protocol called fix (financial
> information exchange)
> Basically the server receives a text string and answers with a text string
> also.
> The protocol is pretty simple, and it consists in a series of fields
> separated by the char alt+1:☺
>
> $message1="8=FIX.4.0.c☺35=A☺9998=D3765☺9997=4443734☺9996=Bara☺";
> It is supposed that I will receive an answer from the server that should be:
> $message2="8=FIX.4.0.c☺35=A☺52=10/24/2006 10:30:34 AM☺100=PFG☺";
> The server talks TCP, as stated by its owner, and it can be accessed at some
> ip and some port.
>
> Well, trying to keep it simple, I wrote this script:
>
You should always include "use strict; use warnings;" at the start of your
scripts, even simple ones.
>
> use IO::Socket;
Shouldn't that be "use IO::Socket::INET;" ?
>
> $message1="8=FIX.4.0.c☺35=A☺9998=D3765☺9997=4443734☺9996=Bara☺";
> $host="11.35.72.194";
> $port="1000";
No need to quote numbers.
> $handle = IO::Socket::INET->new(Proto => "tcp",
> PeerAddr => $host,
> PeerPort => $port,
> # Reuse => "1",
> # Listen => "1",
> Type => SOCK_STREAM)
Type is implied by Proto.
> or die "can't connect to port $port on $host: $!";
>
> $handle->autoflush(1); # so output gets there right away
Should be enabled already.
> print STDERR "[Connected to $host:$port]\n";
> #up to here, the connection worked fine
> if($handle){print "ok, it worked!\n";}
>
> #now I write to the socket:
> print $handle $message1;
>
> #now I hope to get the answer
> $response=<$handle>;
> print $response;
> #I should have received the same as $message2. Instead, the run hangs and
> nothing happen.
That may be because you are waiting for an input record separator (special
variable $/ default "\n"), and the other end is not sending it.
>
> Am I doing the right thing to enter in conversation with an TCP server?
>
> Thank you to anyone that can shed some litght. Maybe I should ask something
> more to the server owner? What?
It depends on the protocol. Unless there is a string that you can use to
separate messages (I am not familiar with FIX but that doesn't seem to be the
case) you may have to use sys_read and non-blocking I/O, possibly using
IO::Select. Alternatively, you could possibly read the input stream field at a
time, as each field appears to be terminated by '\001', and construct messages.
Also, I did a quick google on FIX, and the information I found suggested that
messages have a header and trailer that contain mandatory fields that do not
appear to be in your examples. If so, that may be a reason why the server is
not responding at all. I could be wrong though.
HTH
--
Brian Raven
_________________________________________
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.
_________________________________________
=================================
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