10.4 Connections Collection

Manages the list of client connections.

10.4.1 Count property

Determines the number of client connections on the server.

Syntax

object.Count()

Type

Long.

Attributes

Read-only.

Example

This example determines whether the number of client connections on the server is greater or less than zero, and acts accordingly.

’Usage: Run this sample, make client connections 
’Display client information 
sub srvskt_conns_reset 
   set csrstsrv=CreateObject("UCX:NWSrvSkt") 
   csrstsrv.Port = 8080 
   csrstsrv.Protocol = TCP 
   csrstsrv.Listen = True 
   ’Wait in infinite loop for client connections 
    Print "Listening for client connections "
    Set cs = csrstsrv.Clients 
    while true 
      if (cs.count > 0) Then 
          cs.reset 
          while (cs.hasmoreelements()) 
             set conn = cs.Next() 
              print ("Address: "&conn.Address &" Port: " &conn.port) 
           Wend 
       End if 
     Wend 
End Sub

See Also

10.4.2 Element method

Finds the specified client connection object.

Syntax

object.Element( 
   Index As Variant, 
   [,Port As Long])

Parameters

Index

A long index or address of the client to find.

Port

Optional. The port number of the client connection to find.

Return Values

Connection. Returns a client connection object with the specified address and port.

Example

This example finds the client connection with the index of 0.

’Usage: Run this sample, make client connections 
’Display client information for the first client 
Sub srvskt_conns_element 
   set csrstsrv=CreateObject("UCX:NWSrvSkt") 
   cselesrv.Port = 8080 
   cselesrv.Protocol = TCP 
   cselesrv.Listen = True 
   ’Wait in infinite loop for client connections 
   Print "Listening for client connections "
   Set cs = cselesrv.Clients 
   while true 
     if (cs.count > 0) Then 
        set conn = cs.Element(0) 
          print ("First client address: "&conn.Address &" Port: " &conn.port) 
        ’Disconnect 
         cs.RemoveElement(0) 
      End if 
    Wend 
End Sub

See Also

10.4.3 HasMoreElements method

Determines whether or not any more client connection objects exist in the collection.

Syntax

object.HasMoreElements()

Parameters

None.

Return Values

Boolean. Returns TRUE if the collection contains more client connection objects; otherwise, FALSE.

Example

This example determines whether or not more client connection objects exist in the collection.

’Usage: Run this sample, make client connections 
’Display client information 
Sub srvskt_conns_reset 
   set csrstsrv=CreateObject("UCX:NWSrvSkt") 
   csrstsrv.Port = 8080 
   csrstsrv.Protocol = TCP 
   csrstsrv.Listen = True 
   ’Wait in infinite loop for client connections 
   Print "Listening for client connections "
   Set cs = csrstsrv.Clients 
   while true 
     if (cs.count > 0) Then 
       cs.reset 
       while (cs.hasmoreelements()) 
       set conn = cs.Next() 
          print ("Address: "&conn.Address &" Port: " &conn.port) 
      Wend 
     End if 
   Wend 
End Sub

See Also

10.4.4 Next method

Returns the next Connection object from the collection.

Syntax

object.Next()

Parameters

None.

Return Values

Connection.

Example

This example returns the next Connection object from the collection.

’Usage: Run this sample, make client connections 
’Display client information 
Sub srvskt_conns_reset 
   set csrstsrv=CreateObject("UCX:NWSrvSkt") 
   csrstsrv.Port = 8080 
   csrstsrv.Protocol = TCP 
   csrstsrv.Listen = True 
   ’Wait in infinite loop for client connections 
   print "Listening for client connections "
   Set cs = csrstsrv.Clients 
   while true 
    if (cs.count > 0) Then 
      cs.reset 
      while (cs.hasmoreelements()) 
       set conn = cs.Next() 
         print ("Address: "&conn.Address &" Port: " &conn.port) 
      Wend 
     End if 
   Wend 
End Sub

See Also

10.4.5 RemoveElement method

Removes the specified client connection(s).

Syntax

object.RemoveElement( 
   Index As Variant, 
   [,Port As Long])

Parameters

Index

A long index or address of the client to remove.

Port

Optional. The port number of the client connection to remove.

Return Values

Boolean. Returns TRUE if the client connection is successfully removed; otherwise, FALSE.

Remarks

If the Index parameter specifies the client address with no port number, all connections from that client address are removed.

Example

This example removes the client connection with the address 193.97.92.100.

’Usage: Run this sample, make client connections 
’Disconnect the client from Address "193.97.92.100" 
Sub srvskt_conns_remove 
  set csrmvsrv=CreateObject("UCX:NWSrvSkt") 
  csrmvsrv.Port = 8080 
  csrmvsrv.Protocol = TCP 
  csrmvsrv.Listen = True 
  ’Wait in infinite loop for client connections 
  Print "Listening for client connections "
     while true 
     Wend 
End Sub 
 
Sub csrmvsrv_connect(conn) 
     print "New connection from"" &conn.Address 
     if (conn.Address = "IP:193.97.54.165") Then 
       set cs = csrmvsrv.Clients 
         if (cs.RemoveElement("IP:193.97.54.165")) Then 
           print "Removed a connection from 193.97.92.100" 
         end if 
      End If 
End Sub

10.4.6 Reset method

Resets the client connections on the server.

Syntax

object.Reset()

Parameters

None.

Return Values

Void.

Example

This example resets the client connections on the server.

’Usage: Run this sample, make client connections 
’Display client information 
Sub srvskt_conns_reset 
  set csrstsrv=CreateObject("UCX:NWSrvSkt") 
  csrstsrv.Port = 8080 
  csrstsrv.Protocol = TCP 
  csrstsrv.Listen = True 
  ’Wait in infinite loop for client connections 
     Print "Listening for client connections "
     Set cs = csrstsrv.Clients 
     while true 
       if (cs.count > 0) Then 
         cs.reset 
         while (cs.hasmoreelements()) 
          set conn = cs.Next() 
           print ("Address: "&conn.Address &" Port: " &conn.port) 
          Wend 
        End if 
     Wend 
End Sub

See Also