Server
public protocol Server
A common protocol for Kitura-net Servers
-
A type that will be returned by static
listenmethodDeclaration
Swift
associatedtype ServerType -
A
ServerDelegateused for request handlingDeclaration
Swift
var delegate: ServerDelegate? { get set } -
Port number for listening for new connections.
Declaration
Swift
var port: Int? { get } -
The address of a network interface to listen on, for example “localhost”. The default is nil, which listens for connections 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?) throwsParameters
onport number for new connections (eg. 8080)
addressThe address of the network interface to listen on. Defaults to nil, which means this server will listen on all interfaces.
-
listen(on:Default implementation) Listen for connections on a socket.
Default Implementation
Declaration
Swift
func listen(on port: Int) throwsParameters
onport 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 -> ServerTypeParameters
onport number for accepting new connections
addressThe address of the network interface to listen on. Defaults to nil, which means this server will listen on all interfaces.
delegatethe delegate handler for HTTP connections
Return Value
a new Server instance
-
listen(on:Default implementationdelegate: ) 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 -> ServerTypeParameters
onport number for accepting new connections
delegatethe 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
portport number for new connections (eg. 8080)
errorHandleroptional 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)?) -> ServerTypeParameters
portport number for accepting new connections
delegatethe delegate handler for HTTP connections
errorHandleroptional 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) -> SelfParameters
callbackThe 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) -> SelfParameters
callbackThe 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) -> SelfParameters
callbackThe 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) -> SelfParameters
callbackThe listener callback that will run
Return Value
a Server instance
View on GitHub
Server Protocol Reference