Jump to content
C4 Forums | Control4

ReceivedFromNetwork with UDP only getting 1024 bytes


WildCopperAV

Recommended Posts

I am seding out a UDP request to device and its answer is 1407 bytes long, ive tested in Node.JS and it works.

When doing it from Control4 I only get 1024 bytes, ReceivedFromNetwork is only called once, so I cannot get the remainder of the data.

Is there a way around this?

function test()
 myip = C4:GetMyNetworkAddress()
 C4:NetDisconnect(6998, 2345)
 C4:CreateNetworkConnection (6998, myip)
 C4:NetConnect (6998, 2345, 'UDP')
end

function OnConnectionStatusChanged(idBinding, nPort, strStatus)
 if (idBinding == 6998) then
  if (strStatus == "ONLINE") then
   test_message = "this is a test"
   C4:SendToNetwork(6998, 2345, test_message)
  end
 end
end

function ReceivedFromNetwork(idBinding, nPort, StrData)
 MessagePrint("ReceivedFromNetwork idBinding=" .. idBinding .. " port=" .. nPort)
 len=string.len(StrData)
 MessagePrint("Length=" .. len)
end

 

Link to comment
Share on other sites


The code below works, but this is not the proper way of doing things, we dont want to be using blocking sockets on a Control4!

local socket = require("socket")
local udp = assert(socket.udp())
local udp_data

function test2()

 myip = C4:GetMyNetworkAddress()

 udp:close()
 udp = assert(socket.udp())

 udp:settimeout(1)
 assert(udp:setsockname("*",0))
 assert(udp:setpeername(myip,2345))

 message = "this is a test"

 assert(udp:send(message))
 udp_data = udp:receive()

 if (udp_data ~= nil) then
  MessagePrint(udp_data)
 else
  MessagePrint("UDP request failed")
 end

 udp:close()   
end

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.