Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8699209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:53:42+00:00 2026-06-13T01:53:42+00:00

In current lua sockets implementation, I see that we have to install a timer

  • 0

In current lua sockets implementation, I see that we have to install a timer that calls back periodically so that we check in a non blocking API to see if we have received anything.

This is all good and well however in UDP case, if the sender has a lot of info being sent, do we risk loosing the data. Say another device sends a 2MB photo via UDP and we check socket receive every 100msec. At 2MBps, the underlying system must store 200Kbits before our call queries the underlying TCP stack.

Is there a way to get an event fired when we receive the data on the particular socket instead of the polling we have to do now?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:53:43+00:00Added an answer on June 13, 2026 at 1:53 am

    There are a various ways of handling this issue; which one you will select depends on how much work you want to do.*

    But first, you should clarify (to yourself) whether you are dealing with UDP or TCP; there is no “underlying TCP stack” for UDP sockets. Also, UDP is the wrong protocol to use for sending whole data such as a text, or a photo; it is an unreliable protocol so you aren’t guaranteed to receive every packet, unless you’re using a managed socket library (such as ENet).

    Lua51/LuaJIT + LuaSocket

    Polling is the only method.

    • Blocking: call socket.select with no time argument and wait for the socket to be readable.
    • Non-blocking: call socket.select with a timeout argument of 0, and use sock:settimeout(0) on the socket you’re reading from.

    Then simply call these repeatedly.
    I would suggest using a coroutine scheduler for the non-blocking version, to allow other parts of the program to continue executing without causing too much delay.

    Lua51/LuaJIT + LuaSocket + Lua Lanes (Recommended)

    Same as the above method, but the socket exists in another lane (a lightweight Lua state in another thread) made using Lua Lanes (latest source). This allows you to instantly read the data from the socket and into a buffer. Then, you use a linda to send the data to the main thread for processing.

    This is probably the best solution to your problem.

    I’ve made a simple example of this, available here. It relies on Lua Lanes 3.4.0 (GitHub repo) and a patched LuaSocket 2.0.2 (source, patch, blog post re’ patch)

    The results are promising, though you should definitely refactor my example code if you derive from it.

    LuaJIT + OS-specific sockets

    If you’re a little masochistic, you can try implementing a socket library from scratch. LuaJIT‘s FFI library makes this possible from pure Lua. Lua Lanes would be useful for this as well.

    For Windows, I suggest taking a look at William Adam’s blog. He’s had some very interesting adventures with LuaJIT and Windows development. As for Linux and the rest, look at tutorials for C or the source of LuaSocket and translate them to LuaJIT FFI operations.

    (LuaJIT supports callbacks if the API requires it; however, there is a signficant performance cost compared to polling from Lua to C.)

    LuaJIT + ENet

    ENet is a great library. It provides the perfect mix between TCP and UDP: reliable when desired, unreliable otherwise. It also abstracts operating system specific details, much like LuaSocket does. You can use the Lua API to bind it, or directly access it via LuaJIT’s FFI (recommended).

    * Pun unintentional.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a c++ application that interfaces with lua files. I have a lua
I have some classes in C++ that I would like to expose to Lua.
Current Situation: Direct Binding I have an NSTableView which displays the data that comes
I have programmed a plugin in Lua for a game that sends player information
Current Process: I have a tar.gz file. (Actually, I have about 2000 of them,
For my current project, I've been writing a lot of C/C++ to Lua wrappers.
How do I extract files using Lua? Update: I now have the following code
Current versions of MediaWiki have the front page accessible via http://www.example.com/wiki/index.php/Main_Page Instead of the
Current Solution So I have something very similar to [HttpPost] public ActionResult Upload() {
Does Lua have a builtin sum() function? I can't seem to find one, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.