Skip to main content
Participant
November 27, 2010
Answered

writing to socket with setinterval not working in windows

  • November 27, 2010
  • 1 reply
  • 649 views

Hello Everyone,

I'm trying to stream a big file to my server, and was using 'setInterval' just fine to slowly upload it from OS X, but when I moved my AIR application to a Windows Vista computer, it no longer worked. I started doing some investigation and found out that 'socket.writeBytes' function was not working inside of 'setInterval'. I then moved the code inside of 'setInterval' to outside of it and everythink worked, but obviously it was no longer streaming. Thinking there was something wrong with 'setInterval', I tried it  without the 'socket.writeBytes' function in it, and it started working fine.

Not sure what is happening, but it seems like a bug in the air.Socket code.

Here is my code:

    var socket = new air.Socket();
    socket.addEventListener(air.Event.CONNECT, function(e) {

        var stream = setInterval(function() {

               socket.writeBytes(filePart, 0, filePart.length);

                if (isDone) {
                    clearInterval(stream);
                }

        }, 1000);

    });

    socket.connect("myServer", 80);

P.S. I also tried using 'air.Timer' and it was the same behavior as 'setInterval'.

Thanks for any help.

This topic has been closed for replies.
Correct answer enorton

Hi,

You should use the flush method:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/Socket.html#flush%28%29

"Flushes any accumulated data in the socket's output buffer.

On some operating systems, flush() is called automatically between execution frames, but on other operating systems, such as Windows, the data is never sent unless you call flush() explicitly. To ensure your application behaves reliably across all operating systems, it is a good practice to call the flush() method after writing each message (or related group of data) to the socket."

I hope this helps!

-Erica

1 reply

enortonCorrect answer
Adobe Employee
November 30, 2010

Hi,

You should use the flush method:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/Socket.html#flush%28%29

"Flushes any accumulated data in the socket's output buffer.

On some operating systems, flush() is called automatically between execution frames, but on other operating systems, such as Windows, the data is never sent unless you call flush() explicitly. To ensure your application behaves reliably across all operating systems, it is a good practice to call the flush() method after writing each message (or related group of data) to the socket."

I hope this helps!

-Erica

greghelloAuthor
Participant
December 3, 2010

That was it. Thanks!