SmartFoxServer Silverlight API
RoundTripBench Method
Namespaces ► SmartFoxClientAPI ► SmartFoxClient ► RoundTripBench()()()
Send a roundtrip request to the server to test the connection' speed.
The roundtrip request sends a small packet to the server which immediately responds with another small packet, and causing the {@link SFSEvent#onRoundTripResponse} event to be fired.
The time taken by the packet to travel forth and back is called "roundtrip time" and can be used to calculate the average network lag of 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 void RoundTripBench()

    Public Sub RoundTripBench

    public:
    void RoundTripBench()

Remarks

Sends:
SFSEvent..::.OnRoundTripResponseDelegate

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)
    {

        // 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 += elapsed / 2;
        pingCount++;

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

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

See Also
SFSEvent..::.OnRoundTripResponseDelegate

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