If you want to reconnect after any un-expected disconnections, enable autoReconnect property.
self.swiftStomp.autoReconnect = true
Notice: If you disconnect manually using disconnect() function, and autoReconnect is enable, socket will try to reconnect after disconnection. If this is not thing you want, please disable autoReconnect before call the disconnect().
Subscription
Full Subsribe signature. Please notice to subscribe only when you ensure connected to the STOMP. I suggest do it in the onConnect delegate with connectType == .toStomp
You have full controll for sending messages. Full signature is as follows:
swiftStomp.send(body: "This is message's text body", to: "/app/greeting", receiptId: "msg-\(Int.random(in: 0..<1000))", headers: [:])
Connection Status check
You can check the status of the SwiftStomp by using connectionStatus property:
switch self.swiftStomp.connectionStatus {
case .connecting:
print("Connecting to the server...")
case .socketConnected:
print("Scoket is connected but STOMP as sub-protocol is not connected yet.")
case .fullyConnected:
print("Both socket and STOMP is connected. Ready for messaging...")
case .socketDisconnected:
print("Socket is disconnected")
}
Manual Pinging
You control for sending WebSocket ‘Ping’ messages. Full signature is as follows:
The ‘autoPing’ feature, will send ping command to websocket server, after pingInterval time ellapsed from last sent sendFrame commands (ex: connect, ack, send ….).
Notice: Auto ping is disabled by default. So you have to enable it after you connected to the server. Also please consider, if you disconnect from the server or call disconnect() explicitly, you must call enableAutoPing() again.
To disable the ‘Auto Ping’ functionality, use disableAutoPing().
Test Environment
This example was test with a Spring Boot websocket server with RabbitMQ as an external message broker.
Example
Please refer to the Example for more functionalities
To run the example project, clone the repo, and run pod install from the Example directory first.
Requirements
iOS 10 or above
Installation
CocoaPods
SwiftStomp is available through CocoaPods. To install
it, simply add the following line to your Podfile:
SwiftStomp
An elegent Stomp client for swift, Base on Starscream websocket library.
Fetures
Encoder
.Data
andText
Usage
Setup
Quick initialize with minimum requirements:
Delegate
Implement all delegate methods to handle all STOMP events!
Connect
Full
Connect
signature:If you want to reconnect after any un-expected disconnections, enable
autoReconnect
property.Subscription
Full
Subsribe
signature. Please notice to subscribe only when you ensure connected to the STOMP. I suggest do it in theonConnect
delegate withconnectType == .toStomp
Send Message
You have full controll for sending messages. Full signature is as follows:
Connection Status check
You can check the status of the SwiftStomp by using
connectionStatus
property:Manual Pinging
You control for sending WebSocket ‘Ping’ messages. Full signature is as follows:
You will receive ‘Pong’ message as a response.
Auto Pinging
If you want to ensure your connection will still alive, you can use ‘Auto Ping’ feature. Full signature is as follows:
The ‘autoPing’ feature, will send
ping
command to websocket server, afterpingInterval
time ellapsed from last sentsendFrame
commands (ex:connect
,ack
,send
….).To disable the ‘Auto Ping’ functionality, use
disableAutoPing()
.Test Environment
This example was test with a Spring Boot websocket server with RabbitMQ as an external message broker.
Example
Please refer to the Example for more functionalities
To run the example project, clone the repo, and run
pod install
from the Example directory first.Requirements
Installation
CocoaPods
SwiftStomp is available through CocoaPods. To install it, simply add the following line to your Podfile:
Swift Package Manager
From Xcode 11, you can use Swift Package Manager to add SwiftStomp to your project.
https://github.com/Romixery/SwiftStomp.git
in the “Choose Package Repository” dialog.Author
Ahmad Daneshvar, romixery@gmail.com
License
SwiftStomp is available under the MIT license. See the LICENSE file for more info.