10.3 NWSrvSkt Object

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

All events in the Server Socket component are asynchronous. The syntax given for the events are specific to NSN.

10.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, an IP address is returned. If Protocol is set to SPX, an IPX address is returned.

Example

This example gives the local address of the server.

Set srv=CreateObject("UCX:NWSrvSkt") 
srv.Protocol = TCP 
srv.Port = 80 
Print "Address : " &srv.Address 
Print "Port : " &srv.Port

10.3.2 Advertise property

Determines the service advertising mode.

Syntax

Object.Advertise[=Mode As Boolean]

Type

Boolean.

Attributes

Read/write.

Remarks

Mode is an optional parameter that sets the advertising mode. If this parameter is set to TRUE, the service is advertised using the Service Advertising Protocol (SAP). By default the mode will be set to FALSE and the service advertising is not done.

The ServiceName property cannot be changed while the value of the Advertise property is TRUE.

To advertise the service, set the Boolean parameters for both the Listen property and the Advertise property to TRUE.

For advertising a service only SPX protocol should be used.

Example

This example causes the service to be advertised using the SAP.

Sub srvskt_ServiceName 
  ’Start a service called NSNService and start advertising 
  Set Ssrv=CreateObject("UCX:NWSrvSkt") 
  Ssrv.Protocol = SPX
  Ssrv.Port = 8080 
  Ssrv.ServiceName = "NSNService" 
  Ssrv.ServiceType = 5000 
  Ssrv.Listen = True 
  Ssrv.Advertise = True 
  ’Wait in infinite loop for client connections 
  Print "Listening for client connection on SPX protocol 
  While true 
Wend 
End Sub

10.3.3 Clients property

Returns the collection of client connections.

Syntax

object.Clients()

Type

Connections.

Attributes

Read-only.

Example

This example returns the collection of client connections.

Sub srvskt_Clients 
    ’List all the clients 
     set Csrv=CreateObject("UCX:NWSrvSkt") 
     Csrv.Protocol = TCP 
     Csrv.Port = 8080 
     Csrv.Listen = True 
    ’Wait in infinite loop for client connections 
      Print "Listening for client connection on SPX protocol" 
     while true 
     Wend 
End Sub 
Sub Csrv_connect(conn) 
     Print "Total clients at this time:" &CSrv.count 
     Print "Address  Port" 
     Set clients=CSrv.Clients 
     For Each client in clients 
       Print Client.Address &"   " &Client.port 
     Next 
End Sub

See Also

10.3.4 Listen property

Determines whether or not the server listens for client connections.

Syntax

object.Listen(=Boolean)

Type

Boolean.

Attributes

Read/write.

Remarks

The Boolean parameter sets the listening mode. Assigning a value to this parameter will not block the application. If this parameter is set to TRUE, the service starts listening. If it is set to FALSE (the default), the listening stops. However, while a FALSE setting stops further client connections from being accepted, the server continues to serve the existing connections.

The protocol and port values cannot be changed while the value of the Advertise property is TRUE.

Example

This Listen example sets the server to start listening for client connections.

’Set protocol and port, then listen for client connections 
set srv=CreateObject("UCX:NWSrvSkt") 
srv.protocol = TCP 
srv.Port = 8080 
srv.Listen = True 
print "Server Information" 
print "Protocol : " &srv.Protocol 
print "Address : " &srv.Address 
print "Listening Port : " &srv.Port 
’Wait in infinite loop for client connections 
print "Listening for client connections "
while true 
Wend

See Also

10.3.5 Port property

Gives the server port number to be used for listening for client connections.

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 listening for client connections. This value must be between 1 and 65535 (default=5000).

Example

This example specifies 80 as the port number to be used for listening for client connections.

Sub srvskt_ServiceName 
    ’Start a service called NSNService and start advertising 
     set Ssrv=CreateObject("UCX:NWSrvSkt") 
     Ssrv.Protocol = SPX 
     Ssrv.Port = 8080 
     Ssrv.ServiceName = "NSNService" 
     Ssrv.ServiceType = 5000 
     Ssrv.Listen = True 
     Ssrv.Advertise = True 
    ’Wait in infinite loop for client connections 
      print "Listening for client connection on SPX protocol "
     while true 
     Wend 
End Sub

See Also

10.3.6 Protocol property

Returns or sets the protocol to be used.

Syntax

object.Protocol[=ProtocolConstant As Constant]

Type

ProtocolConstant.

Attributes

Read/write.

Remarks

ProtocolConstant is an optional parameter that sets the protocol to be used. The default is TCP.

See Section A.27, Protocol Constants.

Example

This example sets TCP as the protocol to be used.

’Set protocol and port, then display server information 
set srv=CreateObject("UCX:NWSrvSkt") 
srv.protocol = TCP 
srv.Port = 8080 
print "Server Information" 
print "Protocol : " &srv.Protocol 
print "Address : " &srv.Address 
print "Port : " &srv.Port

10.3.7 ServiceName property

Returns or sets the name of the service to be advertised using Service Advertising Protocol (SAP).

Syntax

object.ServiceName[=Name As String]

Type

Long.

Attributes

Read/write.

Remarks

This property is valid only for SPX protocols.

Name is an optional parameter that sets the name of the service to be advertised using SAP (max=48 characters).

Example

This example sets NSNService as the name of the service to be advertised using the SAP.

Sub srvskt_ServiceName 
  ’Start a service called NSNService and start advertising 
  set Ssrv=CreateObject("UCX:NWSrvSkt") 
  Ssrv.Protocol = SPX 
  Ssrv.Port = 8080 
  Ssrv.ServiceName = "NSNService" 
  Ssrv.ServiceType = 5000 
  Ssrv.Listen = True 
  Ssrv.Advertise = True 
  ’Wait in infinite loop for client connections 
  print "Listening for client connection on SPX protocol "
  while true 
  Wend 
End Sub

10.3.8 ServiceType property

Returns or sets the Bindery object type for the service to be advertised using Service Advertising Protocol (SAP).

Syntax

object.ServiceType[=Value As Long]

Type

Long.

Attributes

Read/write.

Remarks

This property is valid only for SPX protocols.

Value is an optional parameter that represents the Bindery object type (default=5000).

Example

This example sets 5000 as the Bindery object type to be advertised using the SAP.

Sub srvskt_ServiceName 
  ’Start a service called NSNService and start advertising 
   set Ssrv=CreateObject("UCX:NWSrvSkt") 
   Ssrv.Protocol = SPX 
   Ssrv.Port = 8080 
   Ssrv.ServiceName = "NSNService" 
   Ssrv.ServiceType = 5000 
   Ssrv.Listen = True 
   Ssrv.Advertise = True 
   ’Wait in infinite loop for client connections 
   print "Listening for client connection on SPX protocol 
   while true 
   Wend 
End Sub

10.3.9 Connect event

Fires on a client connection request.

Syntax

Sub object_Connect 
   (Client As Connection) 
End Sub

Parameters

Client

An object of the class UCX:NWSrvSkt.Connection.

Return Values

Connection.

Example

This example fires on a client connection request.

’Usage: Run this sample, make a client connection 
Sub srvskt_Connect 
  ’List all the clients 
  set Connsrv=CreateObject("UCX:NWSrvSkt") 
  Connsrv.Port = 8080 
  Connsrv.Protocol = TCP 
  Connsrv.Listen = True 
  ’Wait in infinite loop for client connections 
  Print "Listening for client connections "
  while true 
  Wend 
End sub 
sub Connsrv_connect(conn) 
  print "New connection from Address: " &conn.Address &" Port: " &conn.port 
End Sub

See Also

10.3.10 Disconnect event

Fires when a client disconnects from the server.

Syntax

Sub object_Disconnect 
   (Client As Connection) 
End Sub

Parameters

Client

An object of the class UCX:NWSrvSkt.Connection.

Return Values

Connection.

Example

This Disconnect example fires when a client disconnects from the server.

’Usage: Run this sample, make a client connection, and disconnect the client 
’Display information about the client's disconnecting from the server 

Sub srvskt_disconnect 
    set dconnsrv=CreateObject("UCX:NWSrvSkt") 
    dconnsrv.Port = 8080 
    dconnsrv.Protocol = TCP 
    dconnsrv.Listen = True 
    ’Wait in infinite loop for client connections 
     Print "Listening for client connections "
     while true 
     Wend 
End Sub 
 
Sub dconnsrv_disconnect(Client) 
     print "Disconnect from Address: " &Client.Address &" Port: " &Client.port 
End Sub

See Also

10.3.11 Error event

Fired for socket-related errors.

Syntax

sub object_Error( 
   Number As Integer, 
   Description As String, 
   Client As Connection)

Parameters

Number

The number of the error.

Description

The description of the error.

Client

An object of the class UCX:NWSrvSkt.Connection in which a network-related error has occurred.

Return Values

String. A description of the error.

Example

This Error example fires for socket-related errors.

’Display the error information 
Sub srvskt_Error 
     set errsrv=CreateObject("UCX:NWSrvSkt") 
     errsrv.Port = 8080 
     errsrv.Protocol = TCP 
     errsrv.Listen = True 
 
     ’Try to change port while listening 
     errsrv.port = 8081 
     ’Wait in infinite loop for client connections 
     Print "Listening for client connections "
     while true 
     Wend 
End Sub 
 
Sub errsrv_Error(ErrNum, Desc, client) 
     print "Error in Socket operation" 
     print "Error Number : " &errNum 
     print "Description : " &Desc 
End Sub

See Also

10.3.12 Receive event

Fired upon the arrival of data from a client.

Syntax

sub object_Receive( 
   Client As Connection, 
   Data As String) 
   End Sub

Parameters

Client

An object of the class UCX:NWSrvSkt

Data

The binary data received from the client.

Return Values

String. The data received from the client.

Example

This Receive example fires upon the arrival of data from the client.

’Usage: Run this sample, make a client connection, and send some data from the client 
’Display the data received from the client 
Sub srvskt_receive 
   set rcvsrv=CreateObject("UCX:NWSrvSkt") 
   rcvsrv.Port = 8080 
   rcvsrv.Protocol = TCP 
   rcvsrv.Listen = True 
   ’Wait in infinite loop for client connections 
   Print "Listening for client connections "
   while true 
   Wend 
End Sub 
 
Sub rcvsrv_Receive(Client, Data) 
     print "Received Data from Address: " &Client.Address &" Port: " &Client.port 
     print "Data: " &Data 
End Sub

See Also