Skip to main content
Known Participant
March 3, 2017
Question

DatagramSocket#close() takes 2 seconds

  • March 3, 2017
  • 13 replies
  • 1370 views

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 has been closed for replies.

13 replies

Inspiring
March 27, 2018

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

Known Participant
March 29, 2018

How to avoid 2 seconds UI blocking?

Known Participant
March 9, 2018

Anyone could have a look for this?

PhendraxAuthor
Known Participant
October 11, 2017

Up...

PhendraxAuthor
Known Participant
October 2, 2017

Up again

PhendraxAuthor
Known Participant
June 13, 2017

Up

PhendraxAuthor
Known Participant
June 6, 2017

Up

PhendraxAuthor
Known Participant
May 25, 2017

Up

PhendraxAuthor
Known Participant
May 9, 2017

Youhouuuu

PhendraxAuthor
Known Participant
April 19, 2017

Is there anyone?

PhendraxAuthor
Known Participant
April 10, 2017

Up