Skip to content

IsaiasSantana/ISAWebSocket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ISAWebSocket

Simple WebSocket client on top of the Network framework

Usage

let socket = ISAWebSocket(url: URL(string: "wss://socketurl")!)

socket.delegate = MyDelegate()

socket.startConnection()

.....

final class MyDelegate: ISAWebSocketDelegate {
    func socket(_ socket: WebSocketClient, didReceiveMessage message: SocketMessage) {
        handle(message: message)
    }

    private func handle(message: SocketMessage) {
        switch message {
        case let .string(text):
            break

        case let .data(data):
            break
        }
    }

    func socket(_ socket: WebSocketClient, didReceiveConnectionStatus status: ConnectionStatus) {
        
    }

    func socket(_ socket: WebSocketClient, didReceiveMessage message: Result<SocketMessage, NWError>) {
        
    }

    func socket(_ socket: WebSocketClient, sendMessageDidFailedWithError error: NWError) {
        
    }

    func socket(_ socket: WebSocketClient, didReceivePingPongStatus status: PingPongStatus) {
       
    }
}

Close connection

socket.closeConnection()

Send data

socket.send(message: .string("some_UTF8_String"))

socket.send(message: .data(Data()))

Send ping

socket.sendPing()

Example

https://github.com/IsaiasSantana/ISAWebSocketExample

About

Web socket client on top of the Network framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages