I m using php (the sockets extension) to handle sending and receiving xml files. I d like to be able to fix the outgoing clients port number as the server has a set amount of incoming connections. I find that each time the php script is run it creates a new port number. The client side script I have so far is this:-
send_message( 192.9.2.50 , 10220 ,$xmlCmd->asXML());
function send_message($ipaddr, $port, $msg)
{
$fp = stream_socket_client("tcp://".$ipaddr.":".$port, $errno, $errstr);
if (!$fp)
{
echo "ERR : $errno - $errstr";
}
else
{
fwrite($fp,$msg);
$response = fread($fp,1024);
// Make a SimpleXML object from the response
$xml = new SimpleXMLElement($response);
echo $xml->Channel->Air->Index;
fclose($fp);
}
}
Update:
I ll try using file_get_contents again but the xml only seemed to pass from client to server ie no reply. Could anyone help me with the stream_context_create options, I need to combine these two but can t seem to get it right. Code:-
$opts = array( http =>
array( method => POST ,
header => Content-type: text/xml; ,
content => $msg)
);
//combine with these options
$opts = array( socket =>array( bindto =>"192.9.2.60:2800"));