SmartFoxServer Silverlight API
SFSEvent..::.OnRoundTripResponseDelegate Delegate
Namespaces ► SmartFoxClientAPI ► SFSEvent ► SFSEvent..::.OnRoundTripResponseDelegate
Dispatched when a response to the RoundTripBench()()() request is received.
The "roundtrip time" represents the number of milliseconds that it takes to a message to go from the client to the server and back to the client.
A good way to measure the network lag is to send continuos requests (every 3 or 5 seconds) and then calculate the average roundtrip time on a fixed number of responses (i.e. the last 10 measurements).
Declaration Syntax

C# | Visual Basic | Visual C++

    public delegate void OnRoundTripResponseDelegate(
    	int elapsed
    )

    Public Delegate Sub OnRoundTripResponseDelegate ( _
    	elapsed As Integer _
    )

    public delegate void OnRoundTripResponseDelegate(
    	int elapsed
    )

Parameters

elapsed (Int32)
  the roundtrip time.

Remarks

Version:
SmartFoxServer Basic / Pro

Examples
The following example shows how to check the average network lag time.
CopyC#

    SFSEvent.onRoundTripResponse += OnRoundTripResponse;

    int totalPingTime = 0;
    int pingCount = 0;

    smartFox.RoundTripBench(); // TODO: this method must be called repeatedly every 3-5 seconds to have a significant average value

    public void OnRoundTripResponse(int elapsed)
    {
        int time = elapsed;

        // We assume that it takes the same time to the ping message to go from the client to the server
        // and from the server back to the client, so we divide the elapsed time by 2.
        totalPingTime += time / 2;
        pingCount++;

        int avg = Math.Round(totalPingTime / pingCount);

        Debug.WriteLine("Average lag: " + avg + " milliseconds");
    }

See Also
RoundTripBench()()()

Assembly: SmartFoxClientAPI_Silverlight (Module: SmartFoxClientAPI_Silverlight) Version: 1.0.0.0 (1.0.0.0)