0

I'm trying to send standart PONG frame to the server and use this PONG frame as a heartbeat mechanism as described in the RFC6455.

I'm succeed in sending PONG frame to the server, but I'm kind of stuck with recieveing responce from the server side.

I'm trying to do this like this:

tlsSocket.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);


private function onSocketData(event:ProgressEvent):void
{
//logic goes here
}

The thing is that onSocketData() is not called when ACK frame is recieved in responce of the PONG frame (However, at the web socket initiation this method IS called). Is there any constrains when SOCKET_DATA is fired?

Could somebody point me to my mistakes, please? Thank you!

1 Answer 1

1
+50

The AS3 socket API won't give you any low level information. Afaik this kind of information even isn't even exposed by the OS socket APIs.

SOCKET_DATA will simply be called when there are any bytes available to read from the socket -> The sockets read buffer is not empty. I've you think low level then AS3 drives an event loop which propably uses select or epoll to listen on an OS socket. As soon as this reports that there are bytes available to read then the SOCKET_DATA event will be called so that you can read them.

But why are you at all interested if your PONG was acknowledged? It should not be of any use for you. Just wait for the clients next PING or data packet. If there is an error during transmission AS3 will inform you with an IO_ERROR or CLOSE event. If you want to utilize the websocket PING/PONG mechanism to watchdog clients I would simply use a timer which is started on connect and reset on reception of each PING. If the timer times out close the connection to the client.

Sign up to request clarification or add additional context in comments.

3 Comments

The issue I'm trying to solve is a little bit different: I want to know on the client side if server is online. It is ok while server closes the connecting on graceful shutdown - client closes it's socket as well, but when server got down unexpectedly - client is listening on this socket forever and never knew if this is server outage, or just no notifications is sent via web socket. Thanks for sharing your knowledge, though! Your answer makes things clearer.
Then use the ping/pong messages for implementing a watchdog on client side. You send in ping in regular intervals to the server and start and use a timer to check if pong was received in a specific interval. If you don't receive pong until the timer runs out you assume the server is dead. The websocket standard doesn't say anything about who can send ping or pong messages and in which intervals. It only specifies that you have to send pong messages if you receive ping. You could also do custom ping/pong messages in your application level protocol.
Thanks for support, Matthias! However this is not in accordance RFC this is the best solution in my opinion as well. Thanks once again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.