2
我對Erlang非常陌生,我正在轉換一些PHP的東西,我無法弄清楚這一點。這裏是PHP函數:Erlang二進制包
public function raw_send($string1, $string2 = NULL, $type = SERVERDATA_EXECCOMMAND) {
$data = pack('VV', $this->get_request_id(), $type) . $string1 . chr(0) . $string2 . chr(0); // build data
$packet = pack('V', strlen($data)) . $data;
fwrite($this->fp, $packet, strlen($packet));
}
這是我的嘗試:
raw_send(Sock, String1, String2, Type) ->
RequestId = random:uniform(10),
PacketData = list_to_binary([<<RequestId, Type>>, String1, 0, String2, 0]),
DataLength = byte_size(PacketData),
Packet = list_to_binary([<<DataLength>>, PacketData]),
ok = gen_tcp:send(Sock, Packet).
我使用CRC32比較的東西試過,包( 「VV」,1,3)在PHP應該= < < 1/unsigned-little,3/unsigned-little >>,no?
而且,我想要做的規格:http://developer.valvesoftware.com/wiki/Source_RCON_Protocol
HALP!
謝謝
你的嘗試有什麼問題? – Zed 2010-01-25 11:22:39