Writing binary to a socket..

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
CaptainMaelstrom
Party member
Posts: 161
Joined: Sat Jan 05, 2013 10:38 pm

Re: Writing binary to a socket..

Post by CaptainMaelstrom »

Haha, oh. I was under the impression the argument was in milliseconds.

I looked at some LUBE code I had laying around, and that in conjunction with your help (Boolsheet), I can send and receive data now.

Brings me to my next question :crazy: .

What's the best way to make a drawable image from a string (from ImageData:getString() ) ?

I would think there would be a Image:fromString(string) or ImageData:fromString(string)..
When I try

Code: Select all

function recv(data)
	if data:sub(-4) == 'done' then
		s = s .. data:sub(1,-5)
		local f = love.filesystem.newFile('imgFile.txt')
		f:open('w')
		f:write(s)
		f:close()
		local imgData = love.image.newImageData('imgFile.txt')
		lastImage = love.graphics.newImage(imgData)
		lastReceived = os.time()
		s = ''
	else
		s = s .. data
	end
end
I get a "could not decode image!" error from the

Code: Select all

local imgData = love.image.newImageData('imgFile.txt')
line.
Attachments
serverTest.love
(3.08 KiB) Downloaded 99 times
clientTest.love
(3.06 KiB) Downloaded 117 times
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Writing binary to a socket..

Post by Boolsheet »

There's no best way for that. Not sure if that's changing for 0.9.0.

ImageData:getString gives you raw data and DevIL (the library that loads the images in LÖVE) doesn't understand if you just throw that at it. It's possible to slap a simple header in front of the data to make some image format out of it. RGB is pretty easy, but RGBA and the layout from ImageData:getString makes this trickier. It would require processing in Lua and that's very slow. Perhaps one of the more complicated format works, but that means digging in some heavy specifications.
Shallow indentations.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 72 guests