Server

public protocol Server

A common protocol for Kitura-net Servers

  • A type that will be returned by static listen method

    Declaration

    Swift

    associatedtype ServerType
  • A ServerDelegate used for request handling

    Declaration

    Swift

    var delegate: ServerDelegate? { get set }
  • Port number for listening for new connections.

    Declaration

    Swift

    var port: Int? { get }
  • The address of the network interface to listen on. Defaults to nil, which means this server will listen on all interfaces.

    Declaration

    Swift

    var address: String? { get }
  • A server state.

    Declaration

    Swift

    var state: ServerState { get }
  • Listen for connections on a socket.

    Declaration

    Swift

    func listen(on port: Int, address: String?) throws

    Parameters

    on

    port number for new connections (eg. 8080)

    address

    The address of a network interface to listen on, for example “localhost”. The default is nil, which listens for connections on all interfaces.

  • listen(on:) Default implementation

    Listen for connections on a socket.

    Default Implementation

    Declaration

    Swift

    func listen(on port: Int) throws

    Parameters

    on

    port number for new connections (eg. 8080)

  • Static method to create a new Server and have it listen for connections.

    Declaration

    Swift

    static func listen(on port: Int, address: String?, delegate: ServerDelegate?) throws -> ServerType

    Parameters

    on

    port number for accepting new connections

    address

    The address of a network interface to listen on, for example “localhost”. The default is nil, which listens for connections on all interfaces.

    delegate

    the delegate handler for HTTP connections

    Return Value

    a new Server instance

  • listen(on:delegate:) Default implementation

    Static method to create a new Server and have it listen for connections.

    Default Implementation

    Declaration

    Swift

    static func listen(on port: Int, delegate: ServerDelegate?) throws -> ServerType

    Parameters

    on

    port number for accepting new connections

    delegate

    the delegate handler for HTTP connections

    Return Value

    a new Server instance

  • Listen for connections on a socket.

    Declaration

    Swift

    @available(*, deprecated, message: "use 'listen(on:﹚ throws' with 'server.failed(callback:﹚' instead")
    func listen(port: Int, errorHandler: ((Swift.Error) -> Void)?)

    Parameters

    port

    port number for new connections (eg. 8080)

    errorHandler

    optional callback for error handling

  • Static method to create a new Server and have it listen for connections.

    Declaration

    Swift

    @available(*, deprecated, message: "use 'listen(on:delegate:﹚ throws' with 'server.failed(callback:﹚' instead")
    static func listen(port: Int, delegate: ServerDelegate, errorHandler: ((Swift.Error) -> Void)?) -> ServerType

    Parameters

    port

    port number for accepting new connections

    delegate

    the delegate handler for HTTP connections

    errorHandler

    optional callback for error handling

    Return Value

    a new Server instance

  • Stop listening for new connections.

    Declaration

    Swift

    func stop()
  • Add a new listener for server beeing started

    Declaration

    Swift

    @discardableResult
    func started(callback: @escaping () -> Void) -> Self

    Parameters

    callback

    The listener callback that will run on server successfull start-up

    Return Value

    a Server instance

  • Add a new listener for server beeing stopped

    Declaration

    Swift

    @discardableResult
    func stopped(callback: @escaping () -> Void) -> Self

    Parameters

    callback

    The listener callback that will run when server stops

    Return Value

    a Server instance

  • Add a new listener for server throwing an error

    Declaration

    Swift

    @discardableResult
    func failed(callback: @escaping (Swift.Error) -> Void) -> Self

    Parameters

    callback

    The listener callback that will run when server throws an error

    Return Value

    a Server instance

  • Add a new listener for when listenSocket.acceptClientConnection throws an error

    Declaration

    Swift

    @discardableResult
    func clientConnectionFailed(callback: @escaping (Swift.Error) -> Void) -> Self

    Parameters

    callback

    The listener callback that will run

    Return Value

    a Server instance