Jump to content

Php socket_write byte[]


jearca

Recommended Posts

i have a code in c# and here use GetBytes(msg) for SSlStream.write, here send and received data correctly, here all work fine, now i want to make the same event in php, but here i cant see a SslSteam or similar(i think no problem, becouse i working with socket_connection, and i think SSL is only for security), now for compare i stop the code in c# for see what data is sending and try to convert in php, for send here, i can see a data byte{} in c# and with `
$message=unpack('C*',$message);
` i can convert the string to byte[], comparing with c# value is the same so, here all is ok, my problem is when i try to write the request, becouse in SslStream.write accpet byte[] but socket_write no accept whe i try send `
socket_write($socket, '\n', strlen($message))
` i have a error : socket_write() expects parameter 2 to be string and obvius is becouse socket_write() only accept string, but so.. as i can send my byte[], becouse the server only accept a byte[] please help me
 
PD> my problem is how i can send the byte[], i dont know if can send eq 
socket_write($socket, $message[1], strlen($message)),

or what is which is the right way, note please $message first is a string as the server only accept byte i use unpack for create a $message[] as byte/integer eq with 70 items, etc, here is ok, becouse comparing with my program in c# give the same value(same array), but now i need send this $message[], but i cant becouse $message now is a byte or integer[], and socket_write only aceppt string, please help me

 

Link to comment
https://forums.phpfreaks.com/topic/293305-php-socket_write-byte/
Share on other sites

The equivalent of a c#'s byte[] type in PHP would just be a string. So just send your string, there is no need for the unpack call.

 

socket_write($socket, $message);
I would recommend you use the streams api rather than the socket extension. It is a newer and better supported api. It will also allow you to easily do SSL as well if you need it, which you probably do if your C# code is using SSL.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.