Skip to main content
Known Participant
Mar 3, 2017 4:35 PM UTC
Question

DatagramSocket#close() takes 2 seconds

Hi,

I'm using UDP sockets in my project, and I found that when I close a DatagramSocket, my app freezes for approximatly 2 seconds

I have no idea why this is happening, is it a bug? is there a workaround?

here is a sample code that reproduces the issue:

var s:DatagramSocket = new DatagramSocket();

s.bind();

s.connect("127.0.0.1",9977);

s.receive();

setTimeout(function():void {

    var t:int = getTimer();

    s.close();

    trace((getTimer()-t)+"ms"); // prints "2000ms"

}, 1000);

PS: Also, it would be great if multicast was supported with AIR DatagramSocket!

This topic is closed to new replies. Start a new post to keep the conversation going.

14 replies

Inspiring
Mar 27, 2018 10:10 AM UTC

it does not seem to be a bug it just you're using UDP in a weird way

when you do a bind/connect/receive

you're waiting to receive data, closing the socket right after does not make a lot of sens

the delay you're seeing is probably  due to the asynchronous nature of receive()

see DatagramSocket.receive()

Enables this DatagramSocket object to receive incoming packets on the bound IP address and port.

The function returns immediately. The DatagramSocket object dispatches a data event when a data packet is received.

in short, receive() does not block and is probably polled every N ms to check for data event
and so synchronised with the event loop, when you tell the UDP socket to close it need

to unhook receiving those data event and so need to wait the event loop to do so

Translate
Known Participant
Mar 29, 2018 4:01 AM UTC

How to avoid 2 seconds UI blocking?

Translate
Known Participant
Mar 9, 2018 6:10 AM UTC

Anyone could have a look for this?

Translate
PhendraxAuthor
Known Participant
Oct 11, 2017 2:35 PM UTC

Up...

Translate
PhendraxAuthor
Known Participant
Oct 2, 2017 11:01 AM UTC

Up again

Translate
PhendraxAuthor
Known Participant
Jun 13, 2017 4:34 PM UTC

Up

Translate
PhendraxAuthor
Known Participant
Jun 6, 2017 9:39 AM UTC

Up

Translate
PhendraxAuthor
Known Participant
May 25, 2017 9:17 AM UTC

Up

Translate
PhendraxAuthor
Known Participant
May 9, 2017 3:46 PM UTC

Youhouuuu

Translate
PhendraxAuthor
Known Participant
Apr 19, 2017 8:17 AM UTC

Is there anyone?

Translate
PhendraxAuthor
Known Participant
Apr 10, 2017 1:49 PM UTC

Up

Translate