Page 1 of 2
Building sending stock-trading php system
Posted: Wed Jul 08, 2009 1:19 pm
by jorgeng
Hello!
I am trying to build a php system which will send transactions to
a server on a financial firm (receiver). The firm will then return
status of done transactions to me.
I have been told to do this in php from the firm and have got some
coding-examples. My problem is to do the coding in php since i don't have
much experience in php.
As i see it i have to build a loop which sends data every 10 second,
read the answers from the firm.
The code i have managed to build so far and which doesn't work:
Can someone help me to get the code working?
I have exluded correct ip-address due to restrictions from the firm:
Code: Select all
<?php
$fp = fsockopen("tcp://xx.xx.xx.xx", xxxx, $errno, $errstr);
if (!$fp) {
echo "ERROR: $errno - $errstr<br />\n";
} else {
$szData = '<?xml version="1.0" encoding="Windows-1252" ?>
<Signal xmlns="http://b.se/TESSignal.xsd">
<Version>1.0</Version>
<SignalType>Entry</SignalType>
<PositionType>Long</PositionType>
<Instrument>OMXS30-8LT</Instrument>
<Strategy>RankorTest</Strategy> <Price>889</Price>
<Weight>1</Weight>
<Comment>RankorTest</Comment>
</Signal>';
fwrite($fp, $szData);
print $szData;
print("XML-sträng skickad ");
// Skickar frågor på port xxxx.
$fp2 = fsockopen("tcp://xx.xx.xx.xx", xxxx, $errno, $errstr);
$szData2 = 'info;RankorTest';
fwrite($fp2, $szData2 );
print $szData2;
print("Fråge-sträng skickad på port xxxx");
// $buffer hamnar allt som mottagits ifrån servern
// $fp innehåller din fsockopen connection
while(true)
{
$str = fread($fp2, 1);
$buffer .= $str;
print $buffer;
if($str == "\n")
{
break;
}
}
// fwrite($fp, "\n");
// echo fread($fp, 26);
fclose($fp);
}
?>
Re: Building sending stock-trading php system
Posted: Wed Jul 08, 2009 4:37 pm
by Eric!
jorgeng wrote:
The code i have managed to build so far and which doesn't work:
Can someone help me to get the code working?
Can you clue us in to what does not work? I can see you do not have any loops in there for time. But do the socket functions work?
Re: Building sending stock-trading php system
Posted: Wed Jul 08, 2009 4:38 pm
by requinix
jorgeng wrote:The code i have managed to build so far and which doesn't work:
Doesn't work
how?
Re: Building sending stock-trading php system
Posted: Thu Jul 09, 2009 1:02 am
by jorgeng
I got error:
Warning: fsockopen() [function.fsockopen]: unable to connect to tcp://xx.xx.xx.xx:xxxx (Anslutningsförsöket misslyckades eftersom den anslutna datorn inte svarade inom en viss tid eller på grund av att den etablerade anslutningen till värddatorn inte längre fungerar. ) in C:\Program Files\xampp\htdocs\RankorSystem_TES_6.php on line 2
ERROR: 10060 - Anslutningsförsöket misslyckades eftersom den anslutna datorn inte svarade inom en viss tid eller på grund av att den etablerade anslutningen till värddatorn inte längre fungerar.
Re: Building sending stock-trading php system
Posted: Thu Jul 09, 2009 1:20 am
by SvanteH
jorgeng wrote:I got error:
Warning: fsockopen() [function.fsockopen]: unable to connect to tcp://xx.xx.xx.xx:xxxx (Anslutningsförsöket misslyckades eftersom den anslutna datorn inte svarade inom en viss tid eller på grund av att den etablerade anslutningen till värddatorn inte längre fungerar. ) in C:\Program Files\xampp\htdocs\RankorSystem_TES_6.php on line 2
ERROR: 10060 - Anslutningsförsöket misslyckades eftersom den anslutna datorn inte svarade inom en viss tid eller på grund av att den etablerade anslutningen till värddatorn inte längre fungerar.
Translation from Swedish:
Connection timed out. A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Are you sure that it's the right IP-address you're connecting to?
Can you check with your firewall and see whether it's blocking outbound connections or not?
Re: Building sending stock-trading php system
Posted: Thu Jul 09, 2009 7:57 am
by jorgeng
SvanteH wrote:jorgeng wrote:I got error:
Warning: fsockopen() [function.fsockopen]: unable to connect to tcp://xx.xx.xx.xx:xxxx (Anslutningsförsöket misslyckades eftersom den anslutna datorn inte svarade inom en viss tid eller på grund av att den etablerade anslutningen till värddatorn inte längre fungerar. ) in C:\Program Files\xampp\htdocs\RankorSystem_TES_6.php on line 2
ERROR: 10060 - Anslutningsförsöket misslyckades eftersom den anslutna datorn inte svarade inom en viss tid eller på grund av att den etablerade anslutningen till värddatorn inte längre fungerar.
Translation from Swedish:
Connection timed out. A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Are you sure that it's the right IP-address you're connecting to?
Can you check with your firewall and see whether it's blocking outbound connections or not?
Hmm, how to check outbound connections?
I have windows vista firewall.

Re: Building sending stock-trading php system
Posted: Thu Jul 09, 2009 8:21 am
by Eric!
The easiest way is to turn it off and try the script again. But I have to ask, where is the server that is running the script? Are you testing this on your own local windows server?
Re: Building sending stock-trading php system
Posted: Thu Jul 09, 2009 8:28 am
by jorgeng
Eric! wrote:The easiest way is to turn it off and try the script again. But I have to ask, where is the server that is running the script? Are you testing this on your own local windows server?
Yes, i runt the code in my wamp in internet explorer.
I think that the php code connects to ip xx.xx.xx on port xxxx, is this correct?
I want to connect to the ip xx.xx.xx on port xxxx ant thought fsockopen did that.

Re: Building sending stock-trading php system
Posted: Thu Jul 09, 2009 8:34 am
by Eric!
Not if your firewall blocks it.
Re: Building sending stock-trading php system
Posted: Thu Jul 09, 2009 8:46 am
by jorgeng
Eric! wrote:Not if your firewall blocks it.
I have added the two ports in windows vista firewall with tcp but no success.
I added to own list the ip-address, still no success.
I am stucked so far on this code, after this code i got the error message:
Code: Select all
<?php
$fp = fsockopen("tcp://xx.xx.xx.xx", xxxx, $errno, $errstr);
if (!$fp) {
echo "ERROR: $errno - $errstr<br />\n";
} else {
$szData = '<?xml version="1.0" encoding="Windows-1252" ?>
<Signal xmlns="http://b.se/TESSignal.xsd">
<Version>1.0</Version>
<SignalType>Entry</SignalType>
<PositionType>Long</PositionType>
<Instrument>OMXS30-8LT</Instrument>
<Strategy>RankorTest</Strategy> <Price>889</Price>
<Weight>1</Weight>
<Comment>RankorTest</Comment>
</Signal>';
fwrite($fp, $szData);
print $szData;
print("XML-sträng skickad på port xxxx");
Re: Building sending stock-trading php system
Posted: Thu Jul 09, 2009 12:14 pm
by SvanteH
Try turning the firewall off completely then try.
Re: Building sending stock-trading php system
Posted: Thu Jul 09, 2009 12:36 pm
by jorgeng
SvanteH wrote:Try turning the firewall off completely then try.
I turned off firewall, but still same result, seems that something is wrong.
Is this the right command to login to a receiving site and transmit data?

Re: Building sending stock-trading php system
Posted: Thu Jul 09, 2009 4:59 pm
by Eric!
The host IP could be blocking you too.
Try to telnet to the ip:port that your fsocket is trying to open and see if you can connect that way.
Re: Building sending stock-trading php system
Posted: Fri Jul 10, 2009 2:16 pm
by jorgeng
Eric! wrote:The host IP could be blocking you too.
Try to telnet to the ip:port that your fsocket is trying to open and see if you can connect that way.
Well, i downloaded easyterm:
http://www.arachnoid.com/easyterm/
installed and connected to ip-address and the port-number and then easyterm says
"Disconnected".
I assume this is a progress, what do you think?

Re: Building sending stock-trading php system
Posted: Fri Jul 10, 2009 3:46 pm
by Eric!
I don't know easyterm. You must be using vista and got screwed by the lack of dos and telnet.
It sounds like that port is blocked to me. You should get something like
Code: Select all
c:>telnet http://www.example.com 80 <CR>
Connecting to http://www.example.com....
[at this point the screen will go blank (wait for this to happen) and anything you type will not be echoed back]
HEAD / HTTP/1.1<CR>
Host: http://www.example.com<CR>
<CR>
When it doesn't work you should get something like Connect failed.
Code: Select all
C:> telnet 60.92.12.56 80 <CR>
Connecting To 60.92.12.56...Could not open connection to the host, on port 80: Connect failed.
Talk to the admin running the host you are trying to connect to and tell them what you are trying to do. Perhaps they are using a different port or only accepting SSL connections on XX port or something.....