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.
Gives the local address of the server.
object.Address
String.
Read-only.
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.
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
Determines the service advertising mode.
Object.Advertise[=Mode As Boolean]
Boolean.
Read/write.
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.
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
Returns the collection of client connections.
object.Clients()
Connections.
Read-only.
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
Determines whether or not the server listens for client connections.
object.Listen(=Boolean)
Boolean.
Read/write.
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.
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
Gives the server port number to be used for listening for client connections.
object.Port[=PortNumber As Long]
Long.
Read/write.
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).
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
Returns or sets the protocol to be used.
object.Protocol[=ProtocolConstant As Constant]
ProtocolConstant.
Read/write.
ProtocolConstant is an optional parameter that sets the protocol to be used. The default is TCP.
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
Returns or sets the name of the service to be advertised using Service Advertising Protocol (SAP).
object.ServiceName[=Name As String]
Long.
Read/write.
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).
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
Returns or sets the Bindery object type for the service to be advertised using Service Advertising Protocol (SAP).
object.ServiceType[=Value As Long]
Long.
Read/write.
This property is valid only for SPX protocols.
Value is an optional parameter that represents the Bindery object type (default=5000).
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
Fires on a client connection request.
Sub object_Connect
(Client As Connection)
End Sub
An object of the class UCX:NWSrvSkt.Connection.
Connection.
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
Fires when a client disconnects from the server.
Sub object_Disconnect
(Client As Connection)
End Sub
An object of the class UCX:NWSrvSkt.Connection.
Connection.
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
Fired for socket-related errors.
sub object_Error(
Number As Integer,
Description As String,
Client As Connection)
The number of the error.
The description of the error.
An object of the class UCX:NWSrvSkt.Connection in which a network-related error has occurred.
String. A description of the error.
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
Fired upon the arrival of data from a client.
sub object_Receive(
Client As Connection,
Data As String)
End Sub
An object of the class UCX:NWSrvSkt
The binary data received from the client.
String. The data received from the client.
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