Jump to content
C4 Forums | Control4

How Receive A MultiCast Package From Net?


Jack_Zhou

Recommended Posts


Below is a snippet from the "KNX Routing Gateway" driver, where it sets up the multicast connection for two-way communication with the Routing Gateway over multicast.

Older versions of the Control4 OS (earlier than 2.10.3) required opening up a server socket just to listen for multicast and also creating a network connection to send multicast.  This snippet opens the appropriate connections based on version.

You would use C4:SendToNetwork the same as any other connection to send.  To receive, use ReceivedFromNetwork, and if that is successful, ignore any data coming in from OnServerDataIn.

It's a little janky, but it does work.

RyanE

function CreateMulticastConnection()

  -- KNX Default Multicast is at: 224.0.23.12:3671
  local knx_multicast_addr = Properties["KNX Multicast Address"] or "224.0.23.12"
  local knx_multicast_port = tonumber(Properties["KNX Multicast Port"]) or 3671

  -- Create Network Binding-based connection for multicast sending/receiving (MULTICAST-L)...
  if (IsVersionGreaterThan("2.10.3.0")) then
    C4:CreateNetworkConnection(MULTICAST_BINDING, knx_multicast_addr)
    C4:NetConnect(MULTICAST_BINDING, knx_multicast_port, "MULTICAST-L") -- New 'Listening' connection
    -- Try to join multicast group periodically until success.
    StartConnectionTimer()
  else
    -- Create Server Socket listener for KNX data... ('binding-based' connection only listens on multicast for OS 2.10.3 or greater)
    C4:CreateServer(knx_multicast_port, "", true)

    C4:CreateNetworkConnection(MULTICAST_BINDING, knx_multicast_addr)
    C4:NetConnect(MULTICAST_BINDING, knx_multicast_port, "MULTICAST") -- Legacy 'Send Only' connection
  end
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.