Page 2 of 2
Re: Building sending stock-trading php system
Posted: Tue Jul 14, 2009 2:42 pm
by jorgeng
Maybe I am doing this wrong with sending xml in php.
Is the structure right to send xml-data or has it to be written in another way?
When i connect to the ip-address and the port the sending string must have the
right syntax.
Any idea?

Re: Building sending stock-trading php system
Posted: Tue Jul 14, 2009 4:53 pm
by jorgeng
When i googled i found this on a forum:
Maybe i should use funtion post to send the data?
The forum:
http://www.sephiroth.it/phpBB/archive/i ... -2034.html
Code: Select all
<?php
function sendPost($host,$path,$data)
{
$method = 'POST';
$fp = fsockopen($host, 80);
fputs($fp, "$method $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp,"Content-type: application/x-www-form- urlencoded\r\n");
fputs($fp, "Content-length: " . strlen($data) . "\r\n");
fputs($fp, "Connection: close\r\n\r\n");
while (!feof($fp)) {
$sent .= fgets($fp,128);
}
fclose($fp);
return $sent;
}
/*
usage:
$stringa = "<your_xml/>"
$sent = sendPost("thehost.com","/path/to/file.php", $stringa);
*/
?>
Re: Building sending stock-trading php system
Posted: Wed Jul 15, 2009 1:16 am
by jorgeng
Eric! wrote: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.....
I opened dos-window, write telnet, computer said not found, had to google and found a page how to install telnet in vista, installed, write o xx.xx.xx.xx xxxx and got error:
Ansluter till xx.xx.xx.xx Det gick inte att ansluta till värddatorn, på porten xxxx. Anslutningen misslyckades.
I have to talk to support. The problem is that i have got a paper with connect options and there is nothing written about ssl, just ip and port...

Re: Building sending stock-trading php system
Posted: Fri Aug 07, 2009 8:07 am
by jorgeng
Hi there, I'm back.
Today was a big day, i managed to send the code to the ip-adress and the port, and success, IT WORKED.
The receiver had changed the port number.
Next step is to read the answer from another port and here I'm stuck.
How do you read data from a port?
I have tried this without success:
Code: Select all
<?php
$fp2 = fsockopen("tcp://xx.xx.xx.xx", xxxx, $errno, $errstr);
if (!$fp) {
echo "ERROR: $errno - $errstr<br />\n";
} else {
$szData2 = 'xxxx;xxxx';
fwrite($fp2, $szData2);
$szData2 = ' ';
fwrite($fp2, $szData2);
// print $szData2;
// $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);
}
?>
In the instruction it says that i have to send an empty row after the first row
for that reason i have an extra $szData2.
I only get ERROR: 0 - when i run the code.
Another question, how will i do to autorun this code on the server on my pc start every morning?
I run xampp since this was the easiest way to get php and apache working.
Thanks for answers....

Re: Building sending stock-trading php system
Posted: Fri Aug 07, 2009 4:01 pm
by jorgeng
How do you do to read data from a socket?

Re: Building sending stock-trading php system
Posted: Mon Aug 10, 2009 3:54 am
by jorgeng
I managed to send data by doing fsockopen with ip-address, port-number and then
doing a fwrite.
I am now trying to do the same thing with reading answer by first doing a write
with strategy and then a new write with an empty row, but this doesn't work.
Is there anything wrong in the code?
Code: Select all
<?php
$handle = fsockopen("tcp://xx.xx.xx.xx", xxxx, $errno, $errstr);
$out = 'xxxx;xxxxx';
fwrite($handle, $out);
$out2 = ' ';
fwrite($handle, $out2);
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
echo $contents;
}
fclose($handle);
?>
I got no answer or nothing, ie8 just says ready.
Re: Building sending stock-trading php system
Posted: Mon Aug 10, 2009 5:10 am
by Benjamin
I'm not sure why our members are helping you perform a job you clearly aren't qualified for, but if you post one more line of code without using code tags I'm going to lock this thread.
Re: Building sending stock-trading php system
Posted: Mon Aug 10, 2009 5:18 am
by jorgeng
astions wrote:I'm not sure why our members are helping you perform a job you clearly aren't qualified for, but if you post one more line of code without using code tags I'm going to lock this thread.
I thought this forum was for php questions for beginners, but maybe i am wrong, just super professionals like you...
And who are you to judge if i am qualified to code in php?
I hope you got same answers from experienced programmers when you was a beginner and had beginner questions....

Re: Building sending stock-trading php system
Posted: Mon Aug 10, 2009 5:46 am
by Benjamin
This forum is for PHP developers of all levels of experience. Regardless of your experience however, you must understand that we hold all members to the same standards. Namely:
- You must obey the forum rules
- You must use the appropriate
Code: Select all
tags when posting code in the forums
[*]We don't do homework assignments
[*]We don't do your paid assignments for you[/list]
I hope you understand.
Re: Building sending stock-trading php system
Posted: Mon Aug 10, 2009 6:17 am
by jorgeng
astions wrote:This forum is for PHP developers of all levels of experience. Regardless of your experience however, you must understand that we hold all members to the same standards. Namely:
- You must obey the forum rules
- You must use the appropriate
Code: Select all
tags when posting code in the forums
[*]We don't do homework assignments
[*]We don't do your paid assignments for you[/list]
I hope you understand.[/quote]
If you have been here in forum since 2002 you could give me an answer to my question why the code doesn't work or if i have to code it another way....
Re: Building sending stock-trading php system
Posted: Wed Aug 19, 2009 9:26 am
by jorgeng
And the story goes on.
Since i didn't get any answer here i had to hire a programmer to read the answer from the stock company.
I'am always there, near the goal line.
Now i want to have help with writing xml-data.
The xml-string i want to send looks like this with hard-coded parameters which i now want to replace with symbolic parameters:
Code: Select all
$szData = '<?xml version="1.0" encoding="Windows-1252" ?>
<Signal xmlns="http://b.se/T.xsd">
<Version>1.0</Version>
<SignalType>Entry</SignalType>
<PositionType>Long</PositionType>
<Instrument>OM Sweden:SE0007286893:SEK</Instrument>
<Strategy>WAMPA</Strategy>
<Price>875</Price>
<Weight>1</Weight>
<Comment>WAMPA</Comment>
</Signal>';
My try to replace instrument data and price looks like this and doesn't work:
Code: Select all
$szData = '<?xml version="1.0" encoding="Windows-1252" ?>
<Signal xmlns="http://b.se/T.xsd">
<Version>1.0</Version>
<SignalType>Entry</SignalType>
<PositionType>Long</PositionType>
<Instrument>OM Sweden:' & $isin & ':SEK</Instrument>
<Strategy>WAMPA</Strategy>
<Price>' & $pris & '</Price>
<Weight>1</Weight>
<Comment>WAMPA</Comment>
</Signal>';
]
Anyone knowing how to concatenate parameters in xml-string?
