PeerBase: Was a message actually sent?

Options
fawnha
edited December 2013 in Photon Server
Is there any way to tell if a message was successfully dispatched over the network? I know PeerBase.SendOperationResponse() returns a SendResult which indicates whether the message was queued to be sent but does not indicate whether the message was actually dispatched. For example, if a client disconnects it takes up to a minute before the timeout is detected by Photon. If a message is sent in this time SendOperationRequest() will succeed but the send will fail when the message is actually dispatched from the queue. What I want to do is pass a System.Threading.Tasks.TaskCompletionSource to my send function and set the contained Task to succeeded if the message was dispatched and to faulted if the message failed to be sent and set the Task to faulted. I know PeerBase.OnSendFailed() is called when the send fails (as in the example above) but the function parameters do not indicate the actual message that failed to be sent, only SendParameters, so I can't use this function to set the Task to faulted. Likewise I can't use PeerBase.OnSend() because this function provides no way to detect the actual send that succeeded so this can't be used to set the Task to succeeded.

Comments

  • chvetsov
    Options
    Hi, fawnha.
    It looks like what you ask is not possible to implement on our level.
    First of all it is very dificult to implement.
    And second
    You should understand that network is not reliable. I mean that even if we successfuly sent a message, this does not mean that it will be delivered to client. Message can be lost. This may happen even over Tcp protocol. For instance because client was just disconnected.

    the only reliable way is when you send response from client when client got message and check this response on server. Yes it is not very simple. This way will increase amount of data need to be sent. Also you should check timeouts and make cleanup when client disconnects
  • You call PeerBase.onSend() when a message is sent and PeerBase.onSendFailed() when it fails so you obviously know when a message has been sent and when the send failed. However, there is no way to tell which message failed or succeeded : onSend() just passes the number of bytes sent and onSendFailed() has the result and SendParameters. No identifying information. What is the purpose of these functions? It would be great if we could include some user data when we call any of the send functions which could be passed to onSendFailed() or onSend(). We could then use the user data to handle the message success or failure. For example, I could pass my TaskCompletionSource object and when I got the onSend() or onSendFailed() call I could set the TaskCompletionSource to complete or faulted as appropriate.
  • chvetsov
    Options
    We call OnSend/OnSendFailed when hand over messages from managed part to native.
    As you understand even if you got OnSend it does not guarantee that message will reach client. This even does not guarantee that message will be sent.

    It may happen because just after call to native code we get connection break. And this may happen on any stage while you send a message. So, if it is realy important for you to know either message was sent and received or not, you should use trick i described above

    We will think about your idea of message identification. Idea is good.