Kōtuku
  • Gallery
  • API
  • Wiki
  • GitHub
    • Audio
    • Config
    • Core
    • Display
    • Document
    • Font
    • HTTP
    • Network
    • Regex
    • SVG
    • Tiri
    • Vector
    • XML
    • XQuery
    • XRandR
      • Audio
      • MP3
      • Sound
      • File
      • MetaClass
      • Module
      • StorageDevice
      • Task
      • Thread
      • Time
      • Compression
      • CompressedStream
      • Config
      • LZMAStream
      • Script
      • Tiri
      • XML
      • XQuery
      • Controller
      • BlurFX
      • ColourFX
      • CompositeFX
      • ConvolveFX
      • DisplacementFX
      • FilterEffect
      • FloodFX
      • ImageFX
      • LightingFX
      • MergeFX
      • MorphologyFX
      • OffsetFX
      • RemapFX
      • SourceFX
      • TurbulenceFX
      • WaveFunctionFX
      • Scintilla
      • Bitmap
      • Clipboard
      • Display
      • Document
      • Font
      • Image
      • Pointer
      • Surface
      • SVG
      • ClientSocket
      • HTTP
      • NetClient
      • NetLookup
      • NetServer
      • NetSocket
      • Proxy
      • Gradient
      • GradientConic
      • GradientContour
      • GradientDiamond
      • GradientDiffusion
      • GradientDistal
      • GradientGouraud
      • GradientLinear
      • GradientMesh
      • GradientRadial
      • GradientVoronoi
      • Vector
      • VectorClip
      • VectorColour
      • VectorEllipse
      • VectorFilter
      • VectorGradient
      • VectorGroup
      • VectorImage
      • VectorPath
      • VectorPattern
      • VectorPolygon
      • VectorRectangle
      • VectorScene
      • VectorShape
      • VectorSpiral
      • VectorText
      • VectorTransition
      • VectorViewport
      • VectorWave
      • Linux Builds
      • Windows Builds
      • Customising Your Build
      • Kōtuku Objects
      • Kōtuku In Depth
      • Kōtuku Design Patterns
      • Coding With AI
      • Regex Manual
      • XML Comparisons
      • Tiri Reference Manual
      • Config API
      • Defer Syntax
      • GUI API
      • HTTP Server API
      • I/O API
      • JSON API
      • OAuth API
      • Options API
      • Proxy Server API
      • Tempus API
      • URL API
      • VFX API
      • Widgets
      • RIPL Reference Manual
      • Origo
      • Flute / Unit Testing
      • Tuku
      • Embedded Document Format
      • TDL Reference Manual
      • TDL Tools
      • Action Reference Manual
      • System Error Codes

NetServer Class

Listens for inbound TCP or UDP communication.

The NetServer class extends NetSocket with local bind, listen and accepted-client management. For TCP listeners, each accepted connection is represented by a ClientSocket and grouped by client IP address in NetClient records. For UDP listeners, incoming datagrams are received through the inherited Incoming callback and can be read with RecvFrom().

SSL Server Certificates

For SSL NetServer listeners, custom certificates can be specified using the SSLCertificate field. Both PEM and PKCS#12 formats are supported across all platforms.

Example with PKCS#12 certificate:

netserver = obj.new('netserver', {
   flags = 'SSL',
   port = 8443,
   sslCertificate = 'config:ssl/server.p12',
   sslKeyPassword = 'password123'
})

Example with PEM certificate and separate private key:

netserver = obj.new('netserver', {
   flags = 'SSL',
   port = 8443,
   sslCertificate = 'config:ssl/server.crt',
   sslPrivateKey = 'config:ssl/server.key'
})

If no custom certificate is specified, the framework will automatically use a localhost self-signed certificate for development purposes. For production use, always specify a proper certificate signed by a trusted CA.

Structure

The NetServer class consists of the following fields:

Access
NameTypeComment
 BacklogINTThe maximum number of connections that can be queued against the socket.

Incoming TCP connections to NetServer objects are queued until they are accepted by the object. Setting the Backlog adjusts the maximum number of connections on the queue, which otherwise defaults to 10.

If the backlog is exceeded, subsequent connections to the socket should expect a connection refused error.

 ClientLimitINTThe maximum number of clients (unique IP addresses) that can be connected to a NetServer.

The ClientLimit value limits the maximum number of IP addresses that can be connected to the socket at any one time. For socket limits per client, see the SocketLimit field.

 ClientsOBJECTPTRLists all NetClient records connected to the NetServer.
 SSLCertificateSTRINGSSL certificate file to use for SSL NetServer listeners.

Set SSLCertificate to the path of an SSL certificate file to use when the NetServer is initialised with SSL enabled. The certificate file must be in a supported format such as PEM, CRT, or P12. If no certificate is defined, the NetServer will either self-sign or use a localhost certificate, if available.

 SSLKeyPasswordSTRINGSSL private key password.

If the SSL private key is encrypted, set this field to the password required to decrypt it. If the private key is not encrypted, this field can be left empty.

 SocketLimitINTThe maximum number of sockets that can be connected from a single client IP address.

The SocketLimit value limits how many simultaneous ClientSocket connections may be opened by one NetClient record.

 TotalClientsINTIndicates the total number of clients currently connected to the NetServer.

NetServer maintains a count of the total number of currently connected TCP client sockets. You can read the total number of connections from this field.

Actions

The following actions are currently supported:

ReadReads raw data information from objects.
ERR acRead(*Object, std::span<int8_t> Buffer, INT *Result)
ParameterDescription
BufferA mutable buffer that will receive the data.
ResultThe Read action will write this parameter with the total number of bytes read into the Buffer.
WriteWrites data to objects that provide storage or output services.
ERR acWrite(*Object, std::span<const int8_t> Buffer, INT *Result)
ParameterDescription
BufferA buffer containing the data that will be written to the object.
ResultThis parameter with be updated with the total number of bytes written from the Buffer.

Methods

The following methods are currently supported:

DisconnectClientDisconnects all sockets connected to a specific client IP.
ERR ns::DisconnectClient(OBJECTPTR Object, objNetClient * Client)
ParameterDescription
ClientThe client to be disconnected.

For NetServer listeners with client IP connections, this method will terminate all socket connections made to a specific client IP and free the resources allocated to it. If #Feedback is defined, a DISCONNECTED state message will also be issued for each socket connection.

If only one socket connection needs to be disconnected, please use DisconnectSocket().

Error Codes
OkayOperation successful.
NullArgsFunction call missing argument value(s)
WrongClassThe Client object is not of type NetClient.
DisconnectSocketDisconnects a single socket that is connected to a client IP address.
ERR ns::DisconnectSocket(OBJECTPTR Object, objClientSocket * Socket)
ParameterDescription
SocketThe client socket to be disconnected.

This method will disconnect a socket connection for a given client. If #Feedback is defined, a DISCONNECTED state message will also be issued.

NOTE: To terminate the connection of a socket acting as the client, either free the object or return/raise ERR::Terminate during Incoming feedback.

Error Codes
OkayOperation successful.
NullArgsFunction call missing argument value(s)
WrongClassAn object is not of the required class type
NetServer class documentation © Paul Manias © 2005-2026

NSF Type

NetSocket options

NameDescription
NSF::BROADCASTEnable broadcast (UDP only).
NSF::DISABLE_SERVER_VERIFYDisable SSL server certificate verification for client sockets (testing only).
NSF::KEEP_ALIVEEnable TCP keep-alive probes using operating system defaults.
NSF::LOG_ALLPrint extra log messages.
NSF::MULTI_CONNECTAllow multiple connections from the same IP (NetServer only).
NSF::SSLUse Secure Sockets Layer for all communication.
NSF::SYNCHRONOUSUse synchronous (blocking) network calls.
NSF::UDPUse UDP (connectionless datagram protocol) instead of TCP.
NetServer module documentation © Paul Manias © 2005-2026

NTC Type

NetSocket states

NameDescription
NTC::CONNECTEDThere is an active connection at present.
NTC::CONNECTINGA connection is being established.
NTC::DISCONNECTEDThere is no connection.
NTC::HANDSHAKINGAn SSL connection is being established.
NTC::MULTISTATEA NetServer reports MULTISTATE because accepted ClientSocket objects track their own states.
NTC::RESOLVINGThe host name is being resolved.
NetServer module documentation © Paul Manias © 2005-2026