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
{开发者_JAVA技巧
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"));
http://ilia.ws/archives/51-PHP-bind-support-via-stream-context.html
Do a basic checklist on the network level:
- Is 192.9.2.60 an IP on an actual interface on the server?
- Are there any routing or firewall rules that affect it? In Linux try ``ip route get x.x.x.x src 192.9.2.60'' and iptables -L
- Are there any other settings (eg SELinux) that interfere with PHP from binding to high ports?
- Run a sniffer and see what the server response actually says
精彩评论