Squirrel/Server/Functions/Sockets/SetLostConnFunc

From Liberty Unleashed Wiki
(Difference between revisions)
Jump to: navigation, search
Line 2: Line 2:
 
This function sets a socket handler function for lost connections. Note that you cannot use functions defined inside a class or a namespace. The handler function is called every time a connection has been lost (either a client or a server connection).
 
This function sets a socket handler function for lost connections. Note that you cannot use functions defined inside a class or a namespace. The handler function is called every time a connection has been lost (either a client or a server connection).
  
If the socket acts as a client socket, ie. it is connected to a server, the handler function does not take any arguments. However if the socket is a server socket (ie. different clients can connect to it) the handler function should be in the following format (''clientID'': The ID of the client that lost connection, ''clientIPAddress'': The IP address of the client, ''clientPort'': the port of the client):
+
If the socket acts as a client socket, ie. it is connected to a server, the handler function takes one argument ''oSocket'', the socket object which the disconnection originates from.
  
<code>function FunctionName( int clientID, string clientIPAddress, int clientPort )</code>
+
<code>function FunctionName( obejct oSocket )</code>
 +
 
 +
However if the socket is a server socket (ie. different clients can connect to it) the handler function should be in the following format (''clientID'': The ID of the client that lost connection, ''clientIPAddress'': The IP address of the client, ''clientPort'': the port of the client):
 +
 
 +
<code>function FunctionName( object oSocket, int clientID, string clientIPAddress, int clientPort )</code>
  
 
== Syntax ==
 
== Syntax ==

Revision as of 17:58, 3 January 2011

Home   |   Squirrel Scripting   |   Server Functions   |   Server Events   |   Client Functions   |   Client Events

This function sets a socket handler function for lost connections. Note that you cannot use functions defined inside a class or a namespace. The handler function is called every time a connection has been lost (either a client or a server connection).

If the socket acts as a client socket, ie. it is connected to a server, the handler function takes one argument oSocket, the socket object which the disconnection originates from.

  1. function FunctionName( obejct oSocket )

However if the socket is a server socket (ie. different clients can connect to it) the handler function should be in the following format (clientID: The ID of the client that lost connection, clientIPAddress: The IP address of the client, clientPort: the port of the client):

  1. function FunctionName( object oSocket, int clientID, string clientIPAddress, int clientPort )

Syntax

Socket.SetLostConnFunc can take 2 different lists of parameters. These are:

  1. bool Socket.SetLostConnFunc( string szFuncname )
  1. bool Socket.SetLostConnFunc( function pFunc )

Arguments

  • szFuncname - This is the name of the handler function as a string
  • pFunc - This is a pointer to the handler function (closure)

Example

  1.  
  2. function onScriptLoad( )
  3. {
  4. p_Socket <- NewSocket( "Function" );
  5. p_Socket.SetLostConnFunc( AttemptReconnect );
  6. }
  7.  

On script load this will set the lost connection function to AttemptReconnect.

Notes

The call onScriptLoad was used in in this example. The function NewSocket was also used. More info about these in the corresponding pages.

Related Functions

Personal tools
Namespaces

Variants
Actions
Navigation
scripting
Toolbox