Click here to Skip to main content
14,641,302 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello, i'm trying to duplicate a server send function written in vb, i need it in PHP.
The VB part is :
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

And i'm trying to write somthing in PHP but, even if the write to scoket works, i receive no reply.
here is the dtructure of packet :
[----- Handshake -----------] [-------- Länge ------------] [-B.O. Mark] [XML-String]
0xA7 0x05 0xFE 0xAB 0x?? 0x?? 0x?? 0x?? 0xFF 0xFE 0x?? 0x?? ...

here the PHP code i try...

$message = $xml;
$iHandShake = hexdec("&HABFE05A7");
$iByteOrderMark = hexdec("&HFEFF");

$myBuffer = "";
$myBuffer = $iHandShake;
$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


What I have tried:

The try is in the description of message

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100