创建 TCP 套接字连接并通过 XML 请求发送以获得 XML 响应? [英] Creating a TCP socket connection and sending through a XML request in order to get an XML response?

查看:26
本文介绍了创建 TCP 套接字连接并通过 XML 请求发送以获得 XML 响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

端口是5792,ip是123.123.123.123.我可以将数据发送到 ip,如下所示:

The port is 5792 and the ip is 123.123.123.123. I am able to send data to the ip, like so:

$host = "tcp://123.123.123.123"; 
$port = 5792; 
$errstr = '';
$errno = '';

$fp = fsockopen($host, $port ,$errno, $errstr, 30); 
if (!$fp) {
  print 'COULD NOT CONNECT! <br />';
  echo "$errstr ($errno)<br />\n";
  die();
}
else {
  print 'SUCCESS!<br />'
}

发送似乎也有效:

$message = 'hello';
fputs ($fp, $message );

接收数据时出现的问题:

The problem comes in when receiving data:

print fread($fp, 128);

打印:

hello

...到屏幕上!换句话说,它在呼应我发送的内容.现在,我知道所有消息都封装在一个 XML 元素中.在这个元素中可以放置一个服务请求,它也被封装在一个 XML 元素中.

... to the screen! So in other words, it's echoing what I'm sending it. Now, I know all messages are encapsulated within an XML element. Within this element a service request can be placed, which is also encapsulated in a XML element.

封装的 XML 元素称为ROOT",我可以在其中放置服务请求请求.让我们将我试图完成的实际服务请求称为topUp".

The encapsulated XML element is called "ROOT" and within this I can place the service request request. Let's call the actual service request I'm trying to accomplish "topUp".

  1. 假设有一个名为 ROOT 的根 xml 元素,它封装了服务请求topUp",将此 XML 作为字符串提交的标准方法是什么?
  2. 期望服务器在无法理解您的意思时回应您的请求是否正常?

推荐答案

了解请求命令的 XML 结构至关重要.无论如何,您也可以通过这种方式向您发送命令

It is vital that u know the XML structure of the request command. In any case you can send you command in such a way too

 $message = "<root>"."\n";
 $message .= "<request>topUp</request>"."\n";
 $message .= "</root>"."\n";
 fputs ($fp, $message );

但是除非您发送已定义的请求结构,否则您可能无法获得想要的结果.

But unless you send your request structure defined you might not get the result you want.

这篇关于创建 TCP 套接字连接并通过 XML 请求发送以获得 XML 响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆