Lua-->Java-->ActionScript & the bloody Nullbyte Character
 

Lua-->Java-->ActionScript & the bloody Nullbyte Character

Started by zillion42, 04 March, 2005, 05:51:20

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

zillion42

Hi everyone,

I hope i can find some help in this forum. :)

Maybe I should start with telling u guys that I am a complete Newbie to LUA Scripting, Java or other languages involved in my project, except maybe Action Script to which i have moderate understanding. (Flash)

I am currently trying to develop an Addon for the Flight Simulator Lock On Modern Air Combat which, if I ever finish it, enables Air Traffic Controllers (Fligt Radar) to see the Position of the Airplanes in a Flash Application (Swf).

Lock on Modern Air Combat (LOMAC) utilizes Lua to export Flight information and send it to a remote Host on a specified port.

Which looks like this:


function LuaExportStart()

   local path = "./luasocket.dll"
   local f = assert(loadlib(path, "luaopen_socket"))
   f()
   local host = '127.0.0.1'
   local port = 4242
   if socket then
      c, e = socket.connect(host, port) -- connect to the listener socket
   end

end


function LuaExportActivityNextEvent(t)
   local tNext = t

   local t = LoGetModelTime()
   local name = LoGetPilotName()
   local altBar = LoGetAltitudeAboveSeaLevel()
   local altRad = LoGetAltitudeAboveGroundLevel()
   local pitch, bank, yaw = LoGetADIPitchBankYaw()
   local vel = LoGetVerticalVelocity()
   local speed = LoGetIndicatedAirSpeed()
   local gforce = LoGetAccelerationUnits()

   if c then
      s, e = c:send(string.format("%.2f,%.2f,%.2f,%.2f,%.2f,%.2f\n",altBar,vel,speed,pitch, bank,gforce))

   end


   tNext = tNext + 1.0
   
   return tNext

end


On this Host, I have a Java Multithreading Broadcast Server which then sends the collected Data (Multiple Clients, "pilots") directly to all connected Flash Clients (Radar Controllers) .

AND HERE COMES THE QUESTION

For Flash to accept the incoming String, it must be terminated by a NullByte Character...
Quote* Generic Flash Communication Server.  All communications sent and received
 * are (must be) terminated with a null character ('\0') consistent with
 * the way Flash does socket communications.  Any client which uses this
 * protocol should also work.

HOW DO I ADD THIS NULL CHARACTER TO MY string.format IN LUA ?


I already tried:

c:send(string.format("%.2f,%.2f,%.2f,%.2f,%.2f,%.2f\0\n",altBar,vel,speed,pitch, bank,gforce))



c:send(string.format("%.2f,%.2f,%.2f,%.2f,%.2f,%.2f\n\0",altBar,vel,speed,pitch, bank,gforce))



c:send(string.format("%.2f,%.2f,%.2f,%.2f,%.2f,%.2f\n",altBar,vel,speed,pitch, bank,gforce));c:send(string.char())


Hope someone understands me...  

I know the whole thing might not be exactly elegant, but it's all I have and it already connects to my Flash just it doesn't send nothing...

Thanks in advance

Zillion42

Skrollster

#1
i might be wrong but i think it is \o

that is the letter o and not the number zero

or

\000

SMF spam blocked by CleanTalk