Latest 1.2.7
License MIT
Platforms ios 8.0
Dependencies SocketRocket






Swift 4.0Swift 3.0

Pod Version



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 4+ and 3+ projects.

This is original a fork from AKStompClient (This library is not working right now)


To run the example project, clone the repo, and run pod install from the Example directory first.


  • iOS 8.0+
  • XCode 8.1, 8.2, 8.3
  • XCode 9.0+
  • XCode 10.0 +
  • Swift 3.0, 3.1, 3.2
  • Swift 4.0, Swift 4.1, Swift 4.2


StompClientLib is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "StompClientLib"


import StompClientLib

Once 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")


func stompClientWillDisconnect(client: StompClientLib!, withError error: NSError) {


didReceiveMessageWithJSONBody ( Message Received via STOMP )

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?, withHeader header: [String : String]?, withDestination destination: String) {
print("Destination : (destination)")
print("JSON Body : (String(describing: jsonBody))")

didReceiveMessageWithJSONBody ( Message Received via STOMP as String )

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("DESTIONATION : (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")

How to subscribe and unsubscribe

There are functions for subscribing and unsubscribing.
Note : You should handle your subscribe and unsubscibe 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 object


socketClient.unsubscribe(destination: topic)

Important : You have to send your destination for both subscribe or unsubscribe!

Unsubsribe with header

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)

Auto Reconnect with a given time

You can use this feature if you need to auto reconnect with a spesific 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 with a given time

// Auto Disconnect after 3 sec
socketClient.autoDisconnect(time: 3)

Future Enhancements

  • [x] Complete a working Example
  • [ ] Add Carthage installation option
  • [ ] Add Swift Package Manager installation option
  • [x] XCode 9 compatibility
  • [x] Swift 4 compatibility and tests
  • [ ] Add Quick Testing
  • [ ] Re-write websocket full swift version instead of Facebook’s SocketRocket lib

Change Log

1.2.7 (2018-10-23)

Full Changelog

1.2.6 (2018-10-23)

Full Changelog

Fixed bugs:

  • Error when connected to socket #23

Closed issues:

  • Auto disconnects #11

1.2.5 (2018-10-22)

Full Changelog

Closed issues:

  • Value for "message-id" is always "1" #22
  • Multiple subscription to topics #20
  • I think there is a memory leak for the delegate #19
  • Getting error when framwork is installed in Objective c project #9

    1.2.4 (2018-10-17)

    Full Changelog

Closed issues:

  • didCloseWithCode 1000, reason: nil #21

1.2.3 (2018-10-17)

Full Changelog

Implemented enhancements:

  • How to receive heartbeat? #18

Closed issues:

  • Socket is not getting connected #30
  • didCloseWithCode 1002 #29
  • No response #27
  • didCloseWithCode 1001, reason: "Stream end encountered" #26
  • Stream end encountered #17
  • unsubscribe socketclient #14
  • It not able to connect web socket. #13
  • One of the delegate method is not being called. #12
  • StompClient Disconnection. #10
  • Unable to find a specification for ‘StompClientLib’ #8

1.2.2 (2017-11-03)

Full Changelog

1.2.1 (2017-10-31)

Full Changelog

1.2.0 (2017-10-29)

Full Changelog

Closed issues:

  • Let client decide what to do with stomp frame body #4
  • Send message support #3
  • Error when calling delegate #1

1.1.7 (2017-10-02)

Full Changelog

1.1.6 (2017-08-08)

Full Changelog

0.1.5 (2017-07-10)

Full Changelog

0.1.4 (2017-07-10)

Full Changelog

0.1.3 (2017-07-10)

Full Changelog

0.1.2 (2017-07-08)

Full Changelog

0.1.1 (2017-07-08)

Full Changelog

0.1.0 (2017-07-08)


FreakyCoder, [email protected]


StompClientLib is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "StompClientLib",
    "version": "1.2.7",
    "summary": "Simple STOMP Client library. Swift 3, 4, 4.2 compatible",
    "description": "Simple STOMP Client library, Swift 3, 4, 4.2 compatible. STOMP Protocol let the program subscribe or unsubscribe the topic. It connects the websocket and use the STOMP protocol to subscribe the topic and recieve the message, receipt or even a ping.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "FreakyCoder": "[email protected]"
    "source": {
        "git": "",
        "tag": "1.2.7"
    "social_media_url": "",
    "platforms": {
        "ios": "8.0"
    "source_files": "StompClientLib/Classes/**/*",
    "dependencies": {
        "SocketRocket": []

Pin It on Pinterest

Share This