Squirrel/Server/Functions/Sockets/SetNewConnFunc
Line 3: | Line 3: | ||
This function sets a socket handler function for new 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 made (either the socket has successfully connected to a server or a client has connected the socket). | This function sets a socket handler function for new 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 made (either the socket has successfully connected to a server or a client has connected the socket). | ||
− | If the socket acts as a client socket, ie. it is connected to a server, the handler function takes one argument '' | + | If the socket acts as a client socket, ie. it is connected to a server, the handler function takes one argument ''Socket'', the socket instance which the disconnection originates from. |
− | <code>function FunctionName( | + | <code>function FunctionName( instance Socket )</code> |
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 for the incoming 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 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 for the incoming connection, ''clientIPAddress'': The IP address of the client, ''clientPort'': the port of the client): | ||
− | <code>function FunctionName( int clientID, string clientIPAddress, int clientPort )</code> | + | <code>function FunctionName( instance Socket, int clientID, string clientIPAddress, int clientPort )</code> |
== Syntax == | == Syntax == |
Latest revision as of 18:11, 3 January 2011
This function sets a socket handler function for new 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 made (either the socket has successfully connected to a server or a client has connected the socket).
If the socket acts as a client socket, ie. it is connected to a server, the handler function takes one argument Socket, the socket instance which the disconnection originates from.
function FunctionName( instance Socket )
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 for the incoming connection, clientIPAddress: The IP address of the client, clientPort: the port of the client):
function FunctionName( instance Socket, int clientID, string clientIPAddress, int clientPort )
[edit] Syntax
Socket.SetNewConnFunc can take 2 different lists of parameters. These are:
bool Socket.SetNewConnFunc( string szFuncname )
bool Socket.SetNewConnFunc( function pFunc )
[edit] Arguments
- szFuncname - This is the name of the handler function as a string
- pFunc - This is a pointer to the handler function (closure)
[edit] Example
function onScriptLoad( ) { p_Socket <- NewSocket( "Function" ); p_Socket.SetNewConnFunc( IdentifyToServices ); }
On script load this will set the new connection function to identify to a network services.
(In this example we are connecting the socket to an IRC server)
[edit] Notes
The call onScriptLoad was used in in this example. The function NewSocket was also used. More info about these in the corresponding pages.