3.3 NWCliSkt Object

The top-level object of the Client Socket UCX component. Used to connect to a server.

3.3.1 Address property

Gives the local address of the server.

Syntax

 Object.Address
 

Type

String.

Attributes

Read-only.

Remarks

The address returned is based on the Protocol property setting. If Protocol is set to TCP, the IP address is returned. If Protocol is set to SPX, the IPX address is returned.

Example

This example gives the local address of the server.

 Set Cli=CreateObject("UCX:NWCliSkt") 
 Cli.Port = 80 
 Print "Address: " &cli.Address 
 

3.3.2 Mode property

Specifies the transfer mode of the data.

Syntax

 Object.Mode
 [=ModeConstant As Constant]
 

Type

TransferMode.

Attributes

Read/write.

Remarks

ModeConstant is an optional parameter that can be set to either SYNC (0) or ASYNC (1). If set to ASYNC, the Send method returns immediately. Otherwise, it blocks the processor time until the data is actually transmitted.

See TransferMode Constants.

Example

This example sets the data transfer mode to Synchronous (SYNC).

 Set cli=CreateObject("UCX:NWCliSkt") 
 cli.Protocol = TCP 
 cli.Port = 80 
 cli.Server = "IP:192.97.92.100" 
 cli.Mode = SYNC 
 Print "Mode: "&cli.Mode 
 

3.3.3 Port property

Gives the server port number to be used for establishing a connection.

Syntax

 Object.Port
 [=PortNumber As Long]
 

Type

Long.

Attributes

Read/write.

Remarks

PortNumber is an optional parameter that sets the server port number to be used for establishing a connection.

Example

This example sets 80 as the port number to be used for establishing a connection with the server.

 Set cli=CreateObject("UCX:NWCliSkt") 
 cli.Protocol = TCP 
 cli.Port = 80 
 Print "Port: " &cli.Port
 

3.3.4 Protocol property

Gives the protocol to be used to connect to the server.

Syntax

 Object.Protocol[=ProtocolConstant As Constant]
 

Type

ProtocolConstant.

Attributes

Read/write.

Remarks

ProtocolConstant is an optional parameter that sets the protocol to be used to connect to the server. The default value for the protocol constant is TCP

See Protocol Constants.

Example

This example sets the protocol to be used to connect to the server.

 Set cli=CreateObject("UCX:NWCliSkt") 
 cli.Protocol = SPX 
 cli.Port = 80 
 Print "Protocol: " &cli.Protocol
 

3.3.5 Server property

Gives the server name or address.

Syntax

 Object.Server[=ServerNameAs String]
 

Type

String.

Attributes

Read/write.

Remarks

ServerName is an optional parameter that sets the name of the server to be connected. It can be any of the following:

  • Server name
  • Service name
  • IP address
  • IPX address

Example

This example gives the server name or address.

 Set cli=CreateObject("UCX:NWCliSkt") 
 cli.Protocol = TCP 
 cli.Port = 80 
 cli.Server = "IP:192.97.92.100" 
 Print "Server: " &cli.Server
 

3.3.6 ServiceType property

A Bindery object type for the service that is advertised using Service Advertising Protocol (SAP).

Syntax

 Object.ServiceType[=ServiceType As Long]
 

Type

Long.

Attributes

Read/write.

Remarks

ServiceType is an optional parameter that sets the type of service to be connected.

Example

This example sets the data transfer mode to Synchronous (SYNC).

 Set cli=CreateObject("UCX:NWCliSkt") 
 cli.Protocol = TCP 
 cli.Port = 80 
 cli.Server = "IP:192.97.92.100" 
 cli.Mode = SYNC 
 cli.ServiceType = 1200 
 Print "Service Type: "&cli.ServiceType
 

3.3.7 TimeOut property

Specifies the timeout value in milliseconds.

Syntax

 object.TimeOut
 [=TimeOut As Long]
 

Type

Long.

Attributes

Read/write.

Remarks

TimeOut is an optional parameter that sets the time, in milliseconds, for the timeout operation.

This property is applicable to any SPX protocol. The default value is 5000.

Example

This example sets the timeout value at 6000 milliseconds.

 set cli=CreateObject("UCX:NWCliSkt") 
 cli.Protocol = TCP 
 cli.Port = 80 
 cli.Server = "IP:192.97.92.100" 
 cli.TimeOut = 6000 
 Print "TimeOut: " &cli.TimeOut
 

3.3.8 Connect method

Establishes a connection to the server.

Syntax

 Object.Connect()
 

Parameters

None.

Return Values

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

Remarks

The Connected event is fired after the connection is established.

Example

This example establishes a connection with the server.

 Set cli=CreateObject("UCX:NWCliSkt") 
 cli.Port = 80 
 cli.Server = "IP:193.97.92.100" 
 cli.Mode = SYNC 
 cli.TimeOut = 10000 
 cli.Protocol = TCP 
 If(cli.Connect() = True) Then 
      Print("Connection Successful") 
 Else 
      Print("Connection Failed") 
 End If 
 cli.Disconnect()
 

3.3.9 Disconnect method

Disconnects the connection.

Syntax

 object.Disconnect()
 

Parameters

None.

Return Values

Boolean. Returns TRUE if the server is disconnected successfully. Else returns FALSE.

Example

This example disconnects from the server.

 set cli=CreateObject("UCX:NWCliSkt") 
 cli.Port = 80 
 cli.Server = "IP:193.97.92.100" 
 cli.Mode = SYNC 
 cli.TimeOut = 10000 
 cli.Protocol = TCP 
 cli.Connect() 
 If(cli.Disconnect() = TRUE) Then 
      Print("Disconnected Successfully") 
 Else 
      Print("Unable to disconnect") 
 End If
 

See Also

3.3.10 Send method

Transfers data from the connected server.

Syntax

 object.Send(
    Data As Variant)
 

Parameters

Data
The data to be sent from the server.

Return Values

Boolean. Returns TRUE if the data is sent successfully. Else returns FALSE.

Example

This example sends the text "My Data" across the established connection.

 Set cli=CreateObject("UCX:NWCliSkt") 
 cli.Port = 7 
 cli.Server = "IP:193.97.92.100" 
 cli.Mode = SYNC 
 If(cli.Connect()) Then 
      If(cli.Send("My Data")) Then 
           Print("Data is sent successfully") 
      End If 
 End If 
 cli.Disconnect() 
 

3.3.11 Connected event

Fires on a successful connection.

Syntax

 sub object_Connected()
 

Parameters

None.

Return Values

None.

Example

This example fires the connected event and executes a sub routine to print a message, when the server is connected successfully.

 Set cli=CreateObject("UCX:NWCliSkt") 
 cli.Port = 80 
 cli.Server = "IP:193.97.92.100" 
 cli.Mode = SYNC 
 If(cli.Connect() = True) Then 
      Print("Connection Successful") 
 Else 
      Print("Connection Failed") 
 End If 
 cli.Disconnect() 
 sub cli_Connected() 
      Print "Connected to the server" 
 End sub
 

3.3.12 Disconnected event

Fired once the connection is disconnected.

Syntax

 sub object_Disconnected()
 

Parameters

None.

Return Values

None.

Example

This example fires the connected event and executes a sub routine to print a message, when the server is disconnected successfully.

 set cli=CreateObject("UCX:NWCliSkt") 
 cli.Port = 80 
 cli.Server = "IP:193.97.92.100" 
 cli.Mode = SYNC 
 cli.Protocol = TCP 
 cli.Connect() 
 If(cli.Disconnect()) Then 
      Print("Disconnect Successful") 
 Else 
      Print("Disconnect Failed") 
 End If 
 Sub cli.Disconnected() 
      Print "Disconnected from the server" 
 End sub
 

3.3.13 Error event

Fired for socket-related errors.

Syntax

 sub object_Error(
    Number As Integer, 
    Description As String)
 

Parameters

Number
The number of the error.
Description
The description of the error.

Return Values

None.

Example

This example fires for socket-related errors. In this case, the error is an invalid port number.

 set cli=CreateObject("UCX:NWCliSkt") 
 ’Bad port number is given to cause Error event 
 cli.Port = 74545 
 cli.Server = "IP:193.97.92.100" 
 cli.Mode = SYNC 
 cli.Protocol = TCP 
 If(cli.Connect()) Then 
   Print("connected successfully") 
 End If 
 cli.Disconnect() 
  
 Sub cli_Error(Err_Number, Err_Description) 
      Print "The error is " &Err_Number 
      Print "Description is: " &Err_Description) 
 End Sub
 

3.3.14 Receive event

Fired when the data from the server is received by the client.

Syntax

 sub object_Receive(
    Data As String)
 

Parameters

Data
The binary data received.

Return Values

None.

Example

This example fires the receive event, when the data from the server is received by the client, successfully.

 set cli=CreateObject("UCX:NWCliSkt") 
 cli.Port = 7 
 cli.Server = "IP:193.97.92.100" 
 cli.Mode = SYNC 
 cli.Protocol = TCP 
 If(cli.Connect() = TRUE) Then 
      If(cli.Send("My Data") = True) Then 
           Print("Data is sent successfully") 
      End If 
 End If 
 cli.Disconnect() 
  
 Sub cli_Receive(Data) 
      Print "Receive event is fired" 
      Print("Received data is: " &Data) 
 End Sub