ServerSocket

public class ServerSocket : CustomStringConvertible

A server socket which accepts TCP/IP connections coming to the device on the specified port.

A server socket automatically listens for IPv4 and IPv6 connections.

The server socket listens asynchronously in the background and will notify the delegate about new connections.

  • Delegate, which is notified about new connections and errors which occurred on this server socket

    Declaration

    Swift

    open var delegate:ServerSocketDelegate?
  • Delegate, which is notified about new connections and errors which occurred on this server socket

    Declaration

    Swift

    open var description: String
  • Initializes a new server socket which listens on the specified port.

    This method may throw a SocketError, if the server socket could not be opened. If this happens, make sure that no other service already listens on this port.

    A server socket automatically listens for IPv4 and IPv6 connections.

    If a port below 1024 is used, the process has to be launched with root permissions.

    For HTTP port 80 should be used.

    For HTTPS port 443 should be used.

    Throws

    A SocketError indicating that the server socket could not be opened

    Declaration

    Swift

    public init(port: UInt16) throws

    Parameters

    port

    Port on which the server socket should listen.

  • Closes the server socket so no more connections can be made to it.

    After the server socket was closed, other server sockets may be opened on the same port.

    Declaration

    Swift

    public func close()