JGSL_clientproxy

client proxy for server communicating with client

Title client proxy for server communicating with client
Author(s) LiXizhi
Date 2008/12/25
File script/kids/3DMapSystemNetwork/JGSL_clientproxy.lua

Description

TIP Sample Code

NPL.load("(gl)script/kids/3DMapSystemNetwork/JGSL_clientproxy.lua");
local proxy = Map3DSystem.JGSL.ClientProxy:new({DefaultFile="your_client_neuron_filename.lua"});

Member Functions

ClientProxy:new

 proxy status
local proxystate = {
   -- proxy is reset
   none = nil,
   -- waiting for server response
   waiting = 1,
   -- server already responded, the client can send message at anytime
   ready = 2,
}

------------------------------------
 a server proxy is used by client to communicate with a epoll server. 
------------------------------------
local ClientProxy = {
   -- nil means we are ready to send a packet.
   state = proxystate.none,
   -- the last time the client sends message to a server proxy, this is measured by the local clock.  
   LastSendTime,
   -- the last time the client receives message from the server, this is measured by the local clock. 
   LastReceiveTime,
   -- default neuron file
   DefaultFile = "script/kids/3DMapSystemNetwork/JGSL_client.lua",
   -- proxy role
   UserRole = "guest",
   -- JID 
   jid,
   -- the jabber client to use. if nil, JGSL.GetJC() is used. 
   jc,
   -- whether we have signed in to the server and has its session key in cookies,
   SignedIn,
   -- cookies: nil or a table containing name value pairs, such as {sk="sessionkeyhere"}
   cookies,
   -- default server timeout time
   -- usually if the server is not responding in 20 seconds, we will report to user about connecion lost or unsuccessful. 
   ServerTimeOut = 20000,
}

ClientProxy = ClientProxy;

syntax

function ClientProxy:new (o)

parameters

o  

ClientProxy:Reset

it will send CS_Logout if old connection contains cookies

syntax

function ClientProxy:Reset()

ClientProxy:Send

send a message to server using this proxy.

  • param msg : msg to send
  • param neuronfile : if nil, self.DefaultFile is used.

syntax

function ClientProxy:Send(jid, msg, neuronfile)

parameters

jid  
msg msg to send
neuronfile  

ClientProxy:OnRespond

call this function whenever the proxy has a response from the server. it makes the proxy ready to send another message.

syntax

function ClientProxy:OnRespond()

ClientProxy:UpdateSessionKey

update session key

  • param bInsertToCookie : if true, it will insert sk to cookies, so that sk will be sent along with all subsequent Send calls.

syntax

function ClientProxy:UpdateSessionKey(sk)

parameters

sk  

ClientProxy:IsReady

whether the proxy is in ready state ready state means that the proxy is connected and not waiting for response.

syntax

function ClientProxy:IsReady()

ClientProxy:MakeReady

force the proxy to ready state

syntax

function ClientProxy:MakeReady()

ClientProxy:IsKeepAlive

whether deltaTime is passed since the last time that we send message to server. if return true, we usually need to send a normal update to server to keep the client alive.

  • param deltaTime : in milliseconds. usually several times the normal update interval. If nil, self.KeepAliveInterval is used.

syntax

function ClientProxy:IsKeepAlive(deltaTime)

parameters

deltaTime in milliseconds. usually several times the normal update interval. If nil, self.KeepAliveInterval is used.

ClientProxy:IsTimeOut

return true if we are not receiving server response for too long

syntax

function ClientProxy:IsTimeOut()


This topic: Main > NPL > JGSL_clientproxy
Topic revision: r1 - 2008-02-29 - LiXizhi
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback