我正在尝试复制用vb编写的服务器发送功能,我在PHP中需要它。 VB部分是:
Dim zSendBuffer(zTCPClient.SendBufferSize) As Byte
BitConverter.GetBytes(iHandShake).CopyTo(zSendBuffer, 0)
BitConverter.GetBytes(((uText.Length * 2) + 2)).CopyTo(zSendBuffer, 4)
BitConverter.GetBytes(&HFEFF).CopyTo(zSendBuffer, 8)
Encoding.Unicode.GetBytes(uText).CopyTo(zSendBuffer, 10)
iSendeStatus = SendeStati.Sending
zNetworkStream.Write(zSendBuffer, 0, (10 + (uText.Length * 2)))
iSendeStatus = SendeStati.Processing
我正在尝试用PHP编写东西,但是,即使写到scoket也行,但我没有收到任何回复。 这是数据包的结构: [-----握手-----------] [--------朗格------------] [-B.O.标记] [XML字符串] 0xA7 0x05 0xFE 0xAB 0x ?? 0x ?? 0x ?? 0x ?? 0xFF 0xFE 0x ?? 0x ?? ...
这是我尝试的PHP代码...
$message = $xml;
$iHandShake = hexdec("&HABFE05A7");
$iByteOrderMark = hexdec("&HFEFF");
$myBuffer = "";
$myBuffer = $iHandShake;
$myBuffer.=((strlen($xml)*2)+2);
$myBuffer.=$iByteOrderMark;
$myBuffer.=$xml;
$myBufferUTF8 = utf8_encode($myBuffer);
$byte_array = unpack('C*', $myBufferUTF8);
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
// connect to server
$result = socket_connect($socket, $host, $port) or die("Could not connect to server\n");
// send string to server
socket_write($socket, $myBufferUTF8, strlen($myBufferUTF8)) or die("Could not send data to server\n");
// get server response
$result = socket_read ($socket, 65537) or die("Could not read server response\n");
echo "Reply From Server :".$result;
// close socket
socket_close($socket);
}
我没有收到服务器的答复,我也不知道该怎么办。你能帮我吗?