Hey,
I'm very new to Erlang, and I am converting some of my PHP stuff, and I can't figure this one out. Here is the function in PHP:
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));
}
This is my attempt:
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).
I've tried using crc32 to compare things, pack("VV", 1, 3) in php should = <<1/unsigned-little, 3/unsigned-little>>, no?
Also, specs of what I'm trying to do: http://developer.valvesoftware.com/wiki/Source_RCON_Protocol
Halp!
Thanks