I'm trying to use LOVE2D to make a GUI for a school project. I need to be able to write binary to a luasocket. I can successfully connect at this point, but when I:
Code: Select all
connection:send(5)
Code: Select all
connection:send(5)
Code: Select all
socket.send( string.char( 0x05 ) ) -- send a byte with binary value 5
Fun fact: 0x05 is exactly the same thing in Lua as 5. If 5 does not work, neither will 0x05.Plu wrote:You can use hexadecimal notation to send specific bytes over the line.
Code: Select all
require "scripts/aliases"
require "scripts/helpers"
local socket = require "socket"
function love.load()
client,clientErr = socket.tcp()
connection,connectErr = client:connect('127.2.3.4',1234)
end
function love.update(dt)
end
function love.draw()
if client then lg.print('socket created',20,5) end
if clientErr then lg.print('client error: ' .. clientErr,20,20) end
if connectErr then lg.print('connect error: ' .. connectErr,20,40) end
if connection then lg.print('connection made',20,80) end
if message then lg.print(message,20,100) end
end
-------------------------------
function love.keypressed(k,uc)
if k=='r' then
message = client:receive('*a')
end
end
Code: Select all
require "scripts/aliases"
require "scripts/helpers"
local socket = require "socket"
function love.load()
client,clientErr = socket.tcp()
connection,connectErr = client:connect('127.2.3.4',1234)
end
function love.update(dt)
end
function love.draw()
if client then lg.print('socket created',20,5) end
if clientErr then lg.print('client error: ' .. clientErr,20,20) end
if connectErr then lg.print('connect error: ' .. connectErr,20,40) end
if connection then lg.print('connection made',20,80) end
if message then lg.print(message,20,100) end
end
-------------------------------
function love.keypressed(k,uc)
if k=='r' then
message = client:receive('*a')
end
end
Code: Select all
function love.keypressed(k,uc)
if key=='c' then connection:close() closed = true end
end
Users browsing this forum: No registered users and 13 guests