| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
StompClientLib is a stomp client in Swift. It uses Facebook's SocketRocket as a websocket dependency. SocketRocket is written in Objective-C but StompClientLib's STOMP part is written in Swift and its usage is Swift. You can use this library in your Swift 5+, 4+ and 3+ projects.
Stomp version
To run the example project, clone the repo, and run pod install from the Example directory first.
StompClientLib is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "StompClientLib"github "WrathChaos/StompClientLib"import StompClientLibOnce imported, you can open a connection to your WebSocket server.
var socketClient = StompClientLib()
let url = NSURL(string: "your-socket-url-is-here")!
socketClient.openSocketWithURLRequest(request: NSURLRequest(url: url as URL) , delegate: self)After you are connected, there are some delegate methods that you need to implement.
func stompClientDidConnect(client: StompClientLib!) {
print("Socket is connected")
// Stomp subscribe will be here!
socketClient.subscribe(destination: topic)
// Note : topic needs to be a String object
}func stompClientDidDisconnect(client: StompClientLib!) {
print("Socket is Disconnected")
}Your json message will be converted to JSON Body as AnyObject and you will receive your message in this function
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, akaStringBody stringBody: String?, withHeader header: [String : String]?, withDestination destination: String) {
print("Destination : \(destination)")
print("JSON Body : \(String(describing: jsonBody))")
print("String Body : \(stringBody ?? "nil")")
}Your json message will be converted to JSON Body as AnyObject and you will receive your message in this function
func stompClientJSONBody(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: String?, withHeader header: [String : String]?, withDestination destination: String) {
print("DESTINATION : \(destination)")
print("String JSON BODY : \(String(describing: jsonBody))")
}If you will use STOMP for in-app purchase, you might need to use this function to get receipt
func serverDidSendReceipt(client: StompClientLib!, withReceiptId receiptId: String) {
print("Receipt : \(receiptId)")
}Your error message will be received in this function
func serverDidSendError(client: StompClientLib!, withErrorMessage description: String, detailedErrorMessage message: String?) {
print("Error Send : \(String(describing: message))")
}If you need to control your server's ping, here is your part
func serverDidSendPing() {
print("Server ping")
}There are functions for subscribing and unsubscribing. Note : You should handle your subscribe and unsubscribe methods ! Suggestion : Subscribe to your topic in "stompClientDidConnect" function and unsubcribe to your topic in stompClientWillDisconnect method.
socketClient.subscribe(destination: topic)
// Note : topic needs to be a String objectsocketClient.unsubscribe(destination: topic)Important : You have to send your destination for both subscribe or unsubscribe!
let destination = "/topic/your_topic"
let ack = destination
let id = destination
let header = ["destination": destination, "ack": ack, "id": id]
// subscribe
socketClient?.subscribeWithHeader(destination: destination, withHeader: header)
// unsubscribe
socketClient?.unsubscribe(destination: subsId)You can use this feature if you need to auto reconnect with a specific time or it will just try to reconnect every second.
// Reconnect after 4 sec
socketClient.reconnect(request: NSURLRequest(url: url as URL) , delegate: self as StompClientLibDelegate, time: 4.0)// Auto Disconnect after 3 sec
socketClient.autoDisconnect(time: 3)This is just an example. You need to convert to your implementation. #42
let connectFrame = "CONNECT\n login:admin\n passcode:password\n\n\n\0"
socket.write(string: connectFrame)Implemented enhancements:
Closed issues:
Implemented enhancements:
Fixed bugs:
Closed issues:
Merged pull requests:
Closed issues:
Implemented enhancements:
Fixed bugs:
Closed issues:
Merged pull requests:
Fixed bugs:
Closed issues:
Merged pull requests:
Closed issues:
Merged pull requests:
Implemented enhancements:
Closed issues:
Implemented enhancements:
Closed issues:
Fixed bugs:
Closed issues:
Closed issues:
Closed issues:
Implemented enhancements:
Closed issues:
Closed issues:
* This Changelog was automatically generated by github_changelog_generator
FreakyCoder, kurayogun@gmail.com
StompClientLib is available under the MIT license. See the LICENSE file for more info.
| Back | FazBrowse Home | New Git URL |