Giter Site home page Giter Site logo

Duration optional? Forever? about udp HOT 5 CLOSED

kevinelliott avatar kevinelliott commented on August 25, 2024
Duration optional? Forever?

from udp.

Comments (5)

xenoken avatar xenoken commented on August 25, 2024

Hi @kevinelliott, thanks for using udp!
Version 3.0.0 introduces an optional duration parameter for udp.listen(). So now it's possible to listen indefinitely.
To stop listening, please call udp.close() on the udp instance.

from udp.

kevinelliott avatar kevinelliott commented on August 25, 2024

Hi @xenoken ... thank you for the library!

Upon removal of the duration, my application exits immediately and does not receive any UDP packets. I'm assuming now I need some kind of main state loop with sleeps in order to prevent the application from exiting?

from udp.

xenoken avatar xenoken commented on August 25, 2024

That's correct @kevinelliott.
When timeout is specified, udp.listen() returns a future that completes only after the time has run out. When timeout is not specified, udp.listen() returns a future that is already completed (with value true). In the latter case listen() behaves like a synchronous function call that returns immediately.

from udp.

kevinelliott avatar kevinelliott commented on August 25, 2024

Ahh, I see... what I was looking for was a never ending listen... I need to process millions of UDP packets over time.

from udp.

xenoken avatar xenoken commented on August 25, 2024

Yes, udp.listen() is indeed never ending. It will keep listening for packets even though the function returns immediately. for example:

var receiver = await UDP.bind(Endpoint.loopback(port: Port(54321));

var success = await receiver.listen((datagram){
// ...your callback code here...
});

// even though the execution reaches this point, receiver is still listening to udp packets.
// what is required now is a way to prevent the application from exiting.

// ...end of program here...

from udp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.