TGC Codebase Backup



Host/Client Network transfer test by Markus

19th Feb 2013 10:52
Summary

Host/Client Network transfer test



Description

it have 3 buttons, host & client,
the host send data, the client get this data and booth show how much is the transfer
in bytes per second.
remember each frame there will be send some data in sync, its not full speed.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    rem
rem AGK Application
rem

// Network transfer
// MR 19.02.2013

//setsyncrate(0,0)
setsyncrate(60,0)

MainLoop()
end

function MainLoop()

    btnHost=1
    AddVirtualButton(btnHost,20,20,10)
    setvirtualbuttontext(btnHost,"Host")

    btnClient=2
    AddVirtualButton(btnClient,40,20,10)
    setvirtualbuttontext(btnClient,"Client")

    btnExit=3
    AddVirtualButton(btnExit,60,20,10)
    setvirtualbuttontext(btnExit,"Exit")

    t#=timer()

    b=0
    bmax=0

    do
     print("FPS "+str(screenfps()))

     Print("Transfer bytes/s " +str(bmax) )

     if getvirtualbuttonpressed(btnHost)=1
        iNetID=Host()
        h=1
     endif

     if getvirtualbuttonpressed(btnClient)=1
        iNetID=Client()
        c=1
     endif

     if getvirtualbuttonpressed(btnExit)=1 then exit

     if h=1
        b=b+Send(iNetID)
     endif

     if c=1
        b=b+Get(iNetID)
     endif

     if (timer()-t#)=>1.0
        Print("piep")
        t#=timer()
        bmax=b
        b=0
     endif

     Sync()
    loop

endfunction

function Host()

 ret=HostNetwork( "AGKNetwork", "Host", 1025 )

endfunction ret

function Client()

    ret=JoinNetwork( "AGKNetwork", "Client" )
    //ret=JoinNetwork( "192.168.0.100", 1025, "Client" )

endfunction ret

function Send(iNetID)

    b=0

    for m=1 to 100

        iMsgID=CreateNetworkMessage( )
        for i=1 to 128
            AddNetworkMessageInteger( iMsgID, 12345 )
            b=b+4
        next
        SendNetworkMessage( iNetID, 0, iMsgID )

    next

endfunction b

function Get(iNetID)

    m=0
    b=0

    do
        m=m+1
        iMsgID=GetNetworkMessage( iNetID )
        if iMsgID=0 then exit
        for i=1 to 128
            int=GetNetworkMessageInteger(iMsgID)
            b=b+4
        next
        DeleteNetworkMessage( iMsgID )
    loop

    //print(m)

endfunction b