lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Clark Snowdall wrote:
> require 'socket'
> host = "localhost"
> port = 47808
> udp, err = socket.udp()
> if not udp then print(err) os.exit() end
> udp:setoption('broadcast', true)
> err = udp:setsockname(host, port)
> if err == nil then print(err) os.exit() end

This might need to be changed to do what you want. Make sure you're not
getting a 'nil' printed on the screen - in which case the packet is
never being sent.

For a more reliable method of catching socket call errors, use assert():

  assert(udp:setoption('broadcast', true))
  assert(udp:setsockname(host, port))
  -- Do the same for the rest.

See http://www.lua.org/manual/5.1/manual.html#5.1 for the behavior of
assert(); the return values from the socket calls are designed to
interact with it for short scripts like this.

Also, for me udp:setpeername() fails under Linux when I use 'localhost'
in setsockname(). I have to set the host variable to be the local IP
address on the Ethernet interface (to which I want to send). I'm not
sure why this is so - perhaps use INADDR_ANY rather than 'localhost'?

If these are not your problems, then I'm at a loss. I was able to
capture the subnet broadcast packet using Wireshark; it's Ethernet
address was broadcast. I set the filter to 'udp port 47808' and made the
mods mentioned above.

Doug


______________________________________________________________________________________
The information contained in this email transmission may contain proprietary and business 
sensitive information.  If you are not the intended recipient, you are hereby notified that 
any review, dissemination, distribution or duplication of this communication is strictly 
prohibited.  Unauthorized interception of this e-mail is a violation of law.  If you are not 
the intended recipient, please contact the sender by reply email and immediately destroy all 
copies of the original message.

Any technical data and/or information provided with or in this email may be subject to U.S. 
export controls law.  Export, diversion or disclosure contrary to U.S. law is prohibited.  
Such technical data or information is not to be exported from the U.S. or given to any foreign
person in the U.S. without prior written authorization of Elbit Systems of America and the 
appropriate U.S. Government agency.