0
votes

I just want to establish connection with FIX api using host and port (which i gave by puchasing connection) and if i connect successfuly then i send a logon request to login on FIX api and then i rececived server response but the problem is i receive a empty(0) respose

MY CODE IS

<?php
/*
Template Name: connection
*/
?>



<?php
error_reporting(E_ALL);


date_default_timezone_set('Asia/Kolkata');
echo date("YmdH:i:s.ms");


$date =date("Ymd-H:i:s.ms");


/* Get the port . */
$service_port = "(some port no.)";

/* Get the IP address for the target host. */
$address = gethostbyname('.....some host name....');

/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, 0);
if ($socket === false) {
    echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
} else {
    echo "OK.............<br>";
}

echo "................Attempting to connect to '$address' on port '$service_port'......<br>";
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
    echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
} else {
    echo "OK............,<br>";
}

$in = "8=FIX.4.3\0019=149\00135=A\00134=1\00149="SenderCompID"\00152=".$date."\00156="TargetCompID"\00198=0\001108=60\001141=Y\001553="Username"\001554="Password"\00110=161\001";

$out = '';

echo "Sending request...";
socket_write($socket, $in, strlen($in));
echo "OK...........<br>";

echo "<br> ------------------Reading response:-------------------<br>";
$buf = 'This is my buffer.';
if (false !== ($bytes = socket_recv($socket, $buf, 2048, MSG_WAITALL))) {
    echo "Read $bytes bytes from socket_recv(). Closing socket...<br>";
} else {
    echo "socket_recv() failed; reason: " . socket_strerror(socket_last_error($socket)) . "\n";
}
socket_close($socket);

echo $buf . "Message End <br>";
echo "OK.\n\n";
?>

The output I am getting in my XAMPP server page in Wordpress is:

2020031910:11:35.0335OK.............
................Attempting to connect to '(some Host IP Adress)' on port '(port no)'......
OK............,
Sending  request...OK...........

------------------Reading response:-------------------
Read 0 bytes from socket_recv(). Closing socket...
Message End
OK.

I would like to ask some things: 1) Is this occuring because of my code or configuration ? 2) Or is this because of issue at FIX server ? 3) Is there any other method to connect with FIX server?

1
There are cases in which the counterparty simply closes the connection. One of the reasons might be a wrong configuration, i.e. CompIDs. So you need to check with the counterparty.Christoph John

1 Answers

0
votes

It could be you need to change the line

if (false !== ($bytes = socket_recv($socket, $buf, 2048, MSG_WAITALL))) {
  echo "Read $bytes bytes from socket_recv(). Closing socket...<br>";
} else {
  echo "socket_recv() failed; reason: " . socket_strerror(socket_last_error($socket)) . "\n";
}

Why don’t you try using http://www.quickfixengine.org/ it is industry standard.