GithubHelp home page GithubHelp logo

wrathchaos / stompclientlib Goto Github PK

View Code? Open in Web Editor NEW
152.0 9.0 81.0 42.24 MB

Simple STOMP Client library, Swift 3 and 4, 4.2, 5 compatible

Home Page: https://www.freakycoder.com

License: MIT License

Ruby 4.58% Swift 95.42%
ios ios-app swift swift5 apple stomp client websocket stompclient stompclientlib

stompclientlib's Introduction

StompClientLib

License platform Cocoapods

Swift 5.0 Swift 4.2 Swift 3.0 Pod Version Issues

Swift 5+ StompClient Library

Introduction

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.

Supported Stomp Versions

Stomp version

  • 1.1
  • 1.2
  • Might not be worked with 1.0 (Never tested)

Example

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

Requirements

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

Installation

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

Cocoapods

pod "StompClientLib"

Carthage

github "WrathChaos/StompClientLib"

Usage

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.

StompClientLibDelegate

stompClientDidConnect

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
}

stompClientDidDisconnect

func stompClientDidDisconnect(client: StompClientLib!) {
print("Socket is Disconnected")
}

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

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("DESTINATION : \(destination)")
  print("String JSON BODY : \(String(describing: jsonBody))")
}

serverDidSendReceipt

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

serverDidSendError

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

serverDidSendPing

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 unsubscribe methods ! Suggestion : Subscribe to your topic in "stompClientDidConnect" function and unsubcribe to your topic in stompClientWillDisconnect method.

Subscribe

socketClient.subscribe(destination: topic)
// Note : topic needs to be a String object

Unsubscribe

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 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 with a given time

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

Login Passcode Implementation

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)

Future Enhancements

  • Complete a working Example
  • Add Carthage installation option
  • Add Swift Package Manager installation option
  • XCode 9 compatibility
  • Swift 4 compatibility and tests
  • Apple's New Socket for iOS 13 Implementation from stratch

Changelog

Full Changelog

Implemented enhancements:

  • SUBSCRIBE and UNSUBSCRIBE Delegate is missing #16

Closed issues:

  • Error Domain=SRWebSocketErrorDomain Code=2132 "received bad response code from server 403" #86
  • the delegate should be weak #83

1.3.8 (2020-03-08)

Full Changelog

Implemented enhancements:

  • Socket stopped working once I moved from ws//: to wss//: #67
  • Self sign certificate, 400 error #66
  • How to increase output buffer #37

Fixed bugs:

  • unable to install #78
  • Number of received messages is limited #76

Closed issues:

  • Can't find header in initial call #81
  • Can't connect to websocket : received bad response code from server 422 #80
  • I just closed the issue because of the stale & reproducible problem #79
  • unable to install #77
  • stompClientDidConnect not called with Spring boot #73
  • Issue with Cookies in header #71
  • Can't see any Websocket traffic in Charles Proxy #70
  • End of stream error #69
  • Cannot connect with Stomp Websocket when custom header #64
  • Can't connect Socket with Spring Boot 2.x.x #63
  • Multiple clients #48
  • IPV6 #38

Merged pull requests:

1.3.7 (2019-08-26)

Full Changelog

Closed issues:

  • The problem when receiving the messages from the Spring boot. #68

1.3.6 (2019-08-06)

Full Changelog

Implemented enhancements:

Fixed bugs:

  • v1.3.4 replaced my custom header in open socket? #58

Closed issues:

  • Json error: The data couldn’t be read because it isn’t in the correct format. #60

Merged pull requests:

  • Fixed ACK id header and added new ACK type #62 (rodmytro)

1.3.5 (2019-07-25)

Full Changelog

Fixed bugs:

  • StompClientDidConnect not called on a fresh project #51

Closed issues:

  • SendJSONForDict error #57
  • Can't connect to websocket with authorization header #39

Merged pull requests:

  • #58 fix open socket with custom header issue #59 (marain87)

1.3.4 (2019-07-19)

Full Changelog

1.3.3 (2019-07-18)

Full Changelog

Closed issues:

  • Missing merge #55
  • Data garbled problem,help #41

Merged pull requests:

  • String body parameter and ':'-in-header-value fix #56 (Erhannis)

1.3.2 (2019-07-10)

Full Changelog

Implemented enhancements:

  • stompClientWillDisconnect missing #44

1.3.1 (2019-06-14)

Full Changelog

Closed issues:

  • Can I subscribe to multiple topics with one stomp client? #47
  • After subscribing to a topic, how to handle messages from server side? #46
  • socket?.readyState is .OPEN and it never goes to my own "stompClientDidDisconnect" method #45
  • Didconnect function cannot be callback after successful connection #43
  • Login, passcode #42
  • App goes in background lock the kepad the socket disconnected #40
  • stompClientDidConnect not called with Spring boot #35
  • Delegate StompClientDidConnect not called after connect->disconnect->connect #15

1.3.0 (2019-04-30)

Full Changelog

Implemented enhancements:

  • invalidate reconnect #36

Closed issues:

  • Should add Carthage #33
  • Invalid Sec-WebSocket-Accept response #32
  • Socket is disconnected with 1007 code as soon as it connected #31
  • enable Assert (self.readyState != SR_CONNECTING) #24

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)

Full Changelog

* This Changelog was automatically generated by github_changelog_generator

Author

FreakyCoder, [email protected]

License

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

stompclientlib's People

Contributors

2yunseong avatar arl505 avatar erhannis avatar jkim0119 avatar meweraptima avatar rodmytro avatar soledue avatar wanbok avatar wrathchaos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stompclientlib's Issues

Socket is not getting connected

i have tried to connect with socket and my delegate is landing to didSendError always with message
Invalid Sec-WebSocket-Accept response.

why example is adding gateway/websocket to url. is it necessary to add it

After subscribing to a topic, how to handle messages from server side?

I managed to send messages and subscribe to topics. Then in my server side, I sent a message back to the subscribed topic, how does the client receive and handle this message???

Basically the message sent by server is not coming back to this method:

func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, withHeader header: [String : String]?, withDestination destination: String)

SendJSONForDict error

        let dict: [String: Any] = [
            "text": text,
            "chatId": chatId,
            "isReply": false
        ]
        socketClient.sendJSONForDict(dict: dict as AnyObject, toDestination: sendMessagePath)

Use this method to send message in chat, server do not receive any message, but didReceiveMessageWithJSONBody method called when someone send message from android client

v1.3.4 replaced my custom header in open socket?

I am using "openSocketWithURLRequest" function with "connectionHeaders" to set my custom header.
It is normal when I am using v1.3.3 or before. But I upgrade to v1.3.4 my custom header seem to be replaced by line 137 in "connect" function ...
Does anyone have the same problem?

line 137:
// Support for Spring Boot 2.1.x
connectionHeaders = [StompCommands.commandHeaderAcceptVersion:"1.1,1.2"]

Self sign certificate, 400 error

Hi, I tried on development a self signed certificate, but we could not connect.
Using a default no secure it works but it cannot run on a real device.
Do you have any advice?

    self.socketClient = StompClientLib()
    let url = NSURL(string: "wss://192.168.1.134:9002/api/ws")!
    socketClient.openSocketWithURLRequest(request: NSURLRequest(url: url as URL) , delegate: self)
    // auto reconnect
    socketClient.reconnect(request: NSURLRequest(url: url as URL) , delegate: self, time: 15.0)

Error:
didFailWithError: Optional(Error Domain=SRWebSocketErrorDomain Code=2132 "received bad response code from server 400" UserInfo={NSLocalizedDescription=received bad response code from server 400, HTTPResponseStatusCode=400})
2019-08-22 10:14:30.791461+0100 loxy4-app[8836:6292750] [Debug] [main] [WebSocketConnection.swift:60] serverDidSendError(client:withErrorMessage:detailedErrorMessage:) > received bad response code from server 400
didFailWithError: Optional(Error Domain=SRWebSocketErrorDomain Code=2132 "received bad response code from server 400" UserInfo={NSLocalizedDescription=received bad response code from server 400, HTTPResponseStatusCode=400})

Device:
iPhone 6s IOS 12.4
StompClientLib version:
Using StompClientLib (1.3.2)

Unable to find a specification for 'StompClientLib'

Hi,
I have downloaded the example project that you have provided and it is working great, but I'm facing issues while I'm trying to install the pods in to my main project the terminal is throwing an error saying Unable to find a specification for 'StompClientLib'.
I've tried changing with various platform versions( :ios, '9.0', '10.0','11.1') but nothing helped.

terminal

podfile

Cannot connect with Stomp Websocket when custom header

Hi Guy,

In the latest version(1.3.6) I see the Library is supporting spring-boot 2.1.x by code:

        if (connectionHeaders == nil) {
        	connectionHeaders = [StompCommands.commandHeaderAcceptVersion:"1.1,1.2"]
        }

But in case I connect with socket with the custom header by function public func openSocketWithURLRequest(request: NSURLRequest, delegate: StompClientLibDelegate, connectionHeaders: [String: String]?). That means the connectionHeaders is not null, so the connectionHeaders cannot add an accepted version by your code. So I think for fix this, you can add accepted version instance of replace connectionHeaders, like

if (connectionHeaders == nil) {
connectionHeaders = [StompCommands.commandHeaderAcceptVersion:"1.1,1.2"]
} else {
connectionHeaders?[StompCommands.commandHeaderAcceptVersion] = "1.1,1.2"
}

Value for "message-id" is always "1"

I submits some unique id (string) in a header (dictionary) of sendMessage, while sending a message.
But receiver always receives value "1" for "message-id". Original value for "message-id" is replaced with value "1" during message transition.

Other information of header remains same.

My concern behind using this parameter value, reply an acknowledgement to sender. (I can use any other key in header to fulfil my requirement) But I think is message-id is used for the same purpose (acknowledgement)

Error when connected to socket

Hi,
im getting this error didCloseWithCode 1000, reason: Optional(""Session closed by the container because of the idle timeout."") or didCloseWithCode 1001, reason: Optional("Stream end encountered")

it gets connected but when I subscribe y get this errors this is my channel "/wsc/info/user/"

No response

There is no response when I make the connection. didReceiveMessageWithJSONBody does not work at all.

socket?.readyState is .OPEN and it never goes to my own "stompClientDidDisconnect" method

Hi:

I am trying out the library.

In my viewDidLoad(), I put
socketClient.openSocketWithURLRequest(request: NSURLRequest(url: url as URL) , delegate: self as StompClientLibDelegate)

it never reaches the method stompClientDidConnect :
func stompClientDidConnect(client: StompClientLib!) { print("Socket is Connected : ") socketClient.subscribe(destination: "/user/topic/greetings") socketClient.subscribe(destination: "/user/topic/finish") socketClient.autoDisconnect(time: 5) // Reconnect after 4 sec socketClient.reconnect(request: NSURLRequest(url: url as URL) , delegate: self as StompClientLibDelegate, time: 4.0) }

I did some debugging. In StompClientLib.sendFrame(), it always goes into the if statement:

if socket?.readyState == .OPEN { socket?.send(frameString) } else { if let delegate = delegate { DispatchQueue.main.async(execute: { delegate.stompClientDidDisconnect(client: self) }) } }
and skip the else... ... So it never reached my delegate method.

Could you please help me with this?

Getting error when framwork is installed in Objective c project

I'm getting the error mentioned below when I try to import the pod in Objective-C project.
"The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift. This setting can be set in the build settings editor"

Mention version in podspec file to resolve the issue.
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3.0'}

Auto disconnects

Hello
First of all, nice work here!

I'm getting auto disconnected from my web socket after a short amount of time,
I read that this could be solved by setting idleTimerDisabled to YES but wondered if there is a more elegant way to handle this and keep the connection active?

thanks in advance
Pudi

Multiple subscription to topics

Looks like the client fails to subscribe successfully to multiple topics. We receive a 1002 error code back on subscribing to the second topic.
i.e. Let's say, we have two topics to subscribe to, 'Topic ABC' and 'Topic DEF'. The client subscribes to topic 'Topic ABC' successfully, but we get a 1002 error back and the connection closes as soon as I subscribe to 'Topic DEF'. If we reverse the order of subscription, then the client subscribes to topic 'Topic DEF' successfully but fails while subscribing to second topic 'Topic ABC'.

This clearly confirms that there is an issue while subscribing to more than one topics

How to receive heartbeat?

screen shot 2018-02-08 at 11 41 17 am

It works very well on browser, but I dont receive ping on mobile device. The state is connected and heartbeat is 30s.

“CONNECTED\nheart-beat:30000,30000\nuser-name:00udiekv7oJmG5cZk0h7\n\n\0”

Do you have any suggestion?

IPV6

Hi there as you guys know the apple mandatory that your application must support IPV6 if not then they will reject the application they rejected recently my app which was writting in Swift Socket .(who doest not support iv6)
so does StompClientLib support IPV6 ?? kindly reply i am anxiously waiting thanks

StompClientDidConnect not called on a fresh project

Good day,
I see WebSocket is connected, but delegate method StompClientDidConnect never called.

I try example code and in your project it is work fine...
But if I create new project and copy/paste same code, it fail...
I make clean setup swift 5 and 1.3.1 StompClientLib

Multiple clients

Hi, is it possible to have multiple StompClientLib clients that connect to different URL? How can the delegate differentiate the clients?

Thanks in advance!

How to increase output buffer

I am trying to send image as base64 encode over the socket. but socket get disconnected due to outbuffer. how we can increase outputbuffer

Send message support

Perhaps I have missed this in the docs but is there no way to send a STOMP message to a topic using this library?

Thanks

Let client decide what to do with stomp frame body

Hey - nice library and it's working well thanks.

Could we add a new StompClientLibDelegate function that just returns the String optional of the message body rather than an AnyObject?

I send different JSON objects down the wire for different topics and would like to handle the raw JSON string myself:

func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: String?, withHeader header:[String:String]?, withDestination destination: String)

Thanks

Login, passcode

How can I set connection like that?
Where should I enter login and passcode? My delegate methods are not called, getting output frames failed, state 8196
Also I have wss://xxx.com:61024/
Please help.

Screen Shot 2019-05-20 at 19 14 52

didCloseWithCode 1000, reason: nil

An acknowledgement results into disconnection!

 socketClient?.ack(messageId: <#T##String#>)
 socketClient?.ack(messageId: <#T##String#>, withSubscription: <#T##String#>)

When I enable any of above functions (using socketClient instance), it disconnects chat server connection upon receipt of message, with error.

didCloseWithCode 1000, reason: nil

Invalid Sec-WebSocket-Accept response

Hi I’m getting "Invalid Sec-WebSocket-Accept response” error when connect to websocket server developed in java spring boot. Java client is able to successfully connect and send message,

Below is our code implementation

import StompClientLib

   var socketClient = StompClientLib()
    let completedWSURL = "ws://192.168.1.37:8080/iostest/chat"
     let Request = NSMutableURLRequest(url: NSURL(string:completedWSURL)! as URL)
    socketClient.openSocketWithURLRequest(request:Request, delegate: self as        StompClientLibDelegate)

Error response is
Error Domain=SRWebSocketErrorDomain Code=2133 "Invalid Sec-WebSocket-Accept response" UserInfo={NSLocalizedDescription=Invalid Sec-WebSocket-Accept response}

Any help is much appreciated. Thanks in advance.

Json error: The data couldn’t be read because it isn’t in the correct format.

I get data from here jsonBody
How can I get a good format?
override func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, withHeader header: [String : String]?, withDestination destination: String) {

Optional({
dateMessage = 1564591416932;
id = 3608;
idFeed = 3193;
idSender = 996;
linkPhotoAvatar = "https://s3.us-east-1.amazonaws.com/images-views/chat/1553479212385-1553479211398.jpg";
message = Test;
messageViewed = 0;
nameSender = "test3 test";
type = 0;
})
json error: The data couldn’t be read because it isn’t in the correct format.

StompClient Disconnection.

I have been using your stomp client library for a while and its working great ,but the only problem i'm facing is disconnecting the stomp , I've tried calling the
"stompClientDidDisconnect()" and "stompClientWillDisconnect()", where even after unsubscribing the topic i'm still getting the hits from server, Could you please help with the issue?.

didCloseWithCode 1002

Right aftes subscribe a topic, I receive the message:

Error Send : Optional("A subscription identified by 'T_' already exists.")
didCloseWithCode 1002, reason: nil

Can I subscribe to multiple topics with one stomp client?

Hi:

I might be missing something but how can I subscribe to multiple topics with one stomp client?

I tried
socketClient.subscribe(destination: "topic-a")
socketClient.subscribe(destination: "topic-b")

the message sent to topic-a can never be caught by the delegate
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, withHeader header: [String : String]?, withDestination destination: String) { print("DESTIONATION : \(destination)") print("JSON BODY : \(String(describing: jsonBody))") }

  • Evan

stompClientDidConnect not called with Spring boot

Hi,

I know this is more Spring boot question but hopefully, someone can help me here.

I am trying to establish a connection using this lib and Spring boot.

I have a Spring boot project with only one file added:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/topic");
        config.setApplicationDestinationPrefixes("/app");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/hello").withSockJS();
    }

}

I published above code here:
ws://35.159.46.108:8080/hello/websocket

When I start StompClientLib-Example with above ws url I only get
"WebSocket is connected"
and never get
"stompClientDidConnect"

Please help me, thank you.

didCloseWithCode 1001, reason: "Stream end encountered"

I am receiving this error consistently after 60 seconds of successfully establishing a socket connection. Regardless of successfully subscribing and receiving messages from sockets server, the connection will always be closed at approximately 1 minute after connecting.

I can't see any way of configuring the ping/pong functionality or any timeout configuration either.

This renders this library useless.

Is anyone else having this issue? It is a shame because otherwise the library functionality is awesome.

Errors not handled properly

After getting didCloseWithCode 1001, reason: Optional("Stream end encountered") in console, only stompClientDidDisconnect(client:) is being called, stompClientWillDisconnect(client: StompClientLib!, withError error: NSError) is not being called.
Also calling client.isConnected() inside stompClientDidDisconnect(client: StompClientLib!) returns true (I would expect it to be false).

Trying to execute client.disconnect() and making connection again results in calling stompClientDidDisconnect(client: StompClientLib!).

Using latest 1.3.1 StompClientLib.

Data garbled problem,help

Hello,can I ask you some questions about stomp?Will you receive garbled Chinese messages when you use StompClientLib?I am using Stompkit because I use OC,I found that when I received the Chinese message, there would be garbled characters but the English would not.Image is the data processing part,Can you have a try and tell me the result?Thanks
AB5020F8-26CB-4077-B13A-5B261552A4ED
2074FA9B-2092-479D-91D6-D594A98BCB42

Delegate StompClientDidConnect not called after connect->disconnect->connect

	var client = StompClientLib()
	func establishConnection() {
	    if let urlComponents = self.urlComponents, let url = urlComponents.url {
	        client.openSocketWithURLRequest(request: NSURLRequest(url: url) , delegate: self)
	     }
	    }
	    
	func closeConnection() {
	    client.disconnect()
	}

	func stompClientDidConnect(client: StompClientLib!) {
	    Logger.log(message: "StompClientDidConnect", event: .d)
	    let topic = "/user/queue/notifications"
	     Logger.log(message: "Subscribe to topic: \(topic)", event: .d)
	    client.subscribe(destination: topic)
	}

That delegate not even called when I try to reconnect. Please tell me how to fix this? Thank you.

invalidate reconnect

Hi,

Is there a way to invalidate reconnect?

If a user e.g. performs logout than reconnect should stop.

Can't connect to websocket with authorization header

Hi. I get an error while trying to connect to websocket, here is the code:

let request = NSURLRequest(url: url)
socketClient.openSocketWithURLRequest(request: request, delegate: self, connectionHeaders:["Authorization": "Bearer \(token)"])

Response:

received bad response code from server 401

Do you have any ideas why that might be the case?

enable Assert (self.readyState != SR_CONNECTING)

Hi,
im getting this Assert NSAssert(self.readyState != SR_CONNECTING, @"Invalid State: Cannot call send: until connection is open");
in - (void)send:(id)data;

check code ,I think the problem is that :
StompClient.swift 308
socket?.send(StompCommands.commandPing)

maybe I can alter:
if socket?.readyState == .OPEN {
socket?.send(StompCommands.commandPing)
}

Or have other solving??

Error when calling delegate

I keep getting this error. I thought the problem was that delegate was getting deallocated before the library gets to call the delegate method. I moved the delegate to a singleton object and the error is still surfacing. The problem seems to be related to a cast, but I haven't so far found it.

Crashed: com.apple.main-thread
0  libsystem_kernel.dylib         0x182e6d348 __pthread_kill + 8
1  libsystem_pthread.dylib        0x182f81354 pthread_kill$VARIANT$mp + 396
2  libsystem_c.dylib              0x182ddcfd8 abort + 140
3  libswiftCore.dylib             0x105b0162c swift_vasprintf(char**, char const*, char*) + 54
4  libswiftCore.dylib             0x105af71f0 swift::swift_dynamicCastFailure(swift::TargetMetadata<swift::InProcess> const*, swift::TargetMetadata<swift::InProcess> const*, char const*) + 74
5  libswiftCore.dylib             0x105af7268 swift_dynamicCastClass + 118
6  libswiftCore.dylib             0x105b2f89c swift_dynamicCastForeignClass + 82
7  libswiftCore.dylib             0x105afad04 _dynamicCastClassToValueViaObjCBridgeable(swift::OpaqueValue*, swift::OpaqueValue*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetMetadata<swift::InProcess> const*, (anonymous namespace)::_ObjectiveCBridgeableWitnessTable const*, swift::DynamicCastFlags) + 92
8  libswiftCore.dylib             0x105af8fe8 swift_dynamicCast + 568
9  StompClientLib                 0x1055a582c specialized StompClientLib.(webSocket(SRWebSocket!, didFailWithError : Error!) -> ()).(closure #1) (StompClientLib.swift:183)
10 StompClientLib                 0x1055a7af4 partial apply for StompClientLib.(webSocket(SRWebSocket!, didFailWithError : Error!) -> ()).(closure #1) (StompClientLib.swift)
11 StompClientLib                 0x10559ce64 thunk (StompClientLib.swift)
12 libdispatch.dylib              0x182cd9088 _dispatch_call_block_and_release + 24
13 libdispatch.dylib              0x182cd9048 _dispatch_client_callout + 16
14 libdispatch.dylib              0x182ce5b74 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1016
15 CoreFoundation                 0x1832fbf20 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
16 CoreFoundation                 0x1832f9afc __CFRunLoopRun + 2012
17 CoreFoundation                 0x18321a2d8 CFRunLoopRunSpecific + 436
18 GraphicsServices               0x1850abf84 GSEventRunModal + 100
19 UIKit                          0x18c7c7880 UIApplicationMain + 208
20 pingogps                       0x1002c5794 main (AppDelegate.swift:24)
21 libdyld.dylib                  0x182d3e56c start + 4

It not able to connect web socket.

I have a problem.
It not able to connect web socket.

■Source code.

let baseURL = "http://alice2.nem.ninja:7890"
print("URL : (baseURL)")
let url = NSURL(string: baseURL)!
StompClientLib().openSocketWithURLRequest(request: NSURLRequest(url: url as URL) , delegate: self)

■Result

URL : http://alice2.nem.ninja:7890
2018-01-19 02:07:04.566143+0900 TestNem[35284:6662686] [MC] Lazy loading NSBundle MobileCoreServices.framework
2018-01-19 02:07:04.568846+0900 TestNem[35284:6662686] [MC] Loaded MobileCoreServices.framework
didFailWithError: Optional(Error Domain=SRWebSocketErrorDomain Code=2132 "received bad response code from server 404" UserInfo={NSLocalizedDescription=received bad response code from server 404, HTTPResponseStatusCode=404})
Error : Optional("received bad response code from server 404")
2018-01-19 02:08:05.167697+0900 TestNem[35284:6666614] [BoringSSL] Function boringssl_session_errorlog: line 2871 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert
2018-01-19 02:08:05.168153+0900 TestNem[35284:6666614] [BoringSSL] Function boringssl_session_errorlog: line 2871 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert

Is it need to set other parameter??
I want your advice.

Best regards.

Stream end encountered

Sometime I get disconnect issue because of stream end encountered error.

didCloseWithCode 1001, reason: Optional("Stream end encountered")
StompClientDidDisconnect

The server is still in operation. I think this comes from SocketRocket. Do you have any idea about this issue?

unsubscribe socketclient

socketClient?.unsubscribe(destination: "destination string is same as subscribe destination string")

Unsubscription of destination gives following error:

"org.apache.activemq.transport.stomp.ProtocolException: No subscription matched.\r\tat org.apache.activemq.transport.stomp.ProtocolConverter.onStompUnsubscribe(ProtocolConverter.java:734)\r\tat org.apache.activemq.transport.stomp.ProtocolConverter.onStompCommand(ProtocolConverter.java:262)\r\tat org.apache.activemq.transport.ws.AbstractStompSocket.processStompFrame(AbstractStompSocket.java:151)\r\tat org.apache.activemq.transport.ws.jetty9.StompSocket.onWebSocketText(StompSocket.java:96)\r\tat org.eclipse.jetty.websocket.common.events.JettyListenerEventDriver.onTextMessage(JettyListenerEventDriver.java:128)\r\tat org.eclipse.jetty.websocket.common.message.SimpleTextMessage.messageComplete(SimpleTextMessage.java:69)\r\tat org.eclipse.jetty.websocket.common.events.AbstractEventDriver.appendMessage(AbstractEventDriver.java:64)\r\tat org.eclipse.jetty.websocket.common.events.JettyListenerEventDriver.onTextFrame(JettyListenerEventDriver.java:122)\r\tat org.eclipse.jetty.websocket.common.events.AbstractEventDriver.incomingFrame(AbstractEventDriver.java:160)\r\tat org.eclipse.jetty.websocket.common.WebSocketSession.incomingFrame(WebSocketSession.java:309)\r\tat org.eclipse.jetty.websocket.common.extensions.ExtensionStack.incomingFrame(ExtensionStack.java:214)\r\tat org.eclipse.jetty.websocket.common.Parser.notifyFrame(Parser.java:220)\r\tat org.eclipse.jetty.websocket.common.Parser.parse(Parser.java:258)\r\tat org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.readParse(AbstractWebSocketConnection.java:628)\r\tat org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onFillable(AbstractWebSocketConnection.java:476)\r\tat org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)\r\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)\r\tat org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)\r\tat java.lang.Thread.run(Unknown Source)\r")

I think there is a memory leak for the delegate

Hi,
I have read the source code and the example. I think you should make the delegate a weak property, otherwise there is a very high chance to get the strong reference cycle between the delegate and the stompClient object.

stompClientWillDisconnect missing

stompClientWillDisconnect was removed in 2017, but it is still listed in the documentation, and in fact is the suggested place to unsubscribe from a topic: Suggestion : Subscribe to your topic in "stompClientDidConnect" function and unsubcribe to your topic in stompClientWillDisconnect method. Either the method should be re-added, or the documentation should be updated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.