mobile-web-messaging / StompKit

STOMP Objective-C Client for iOS
Apache License 2.0
95 stars 82 forks source link

HTTP GET Header #16

Open jodm opened 10 years ago

jodm commented 10 years ago

Hi.

I have an issue where I am trying to connect to a host with a path (i.e: http://www.url.com/path_1/path_2/websocket) and STOMPKit does not seem to support this.

What I was going to try and do is send a "GET: /path_1/path_2" http header in the method:

The headers are a dictionary it that have to be key/value pairs, I need to send other headers like a token and a country but as you can see when I add my GET header like as the key and the value as blank (@{@"GET /path_1/path_2/websocket": @""} ) it does the following (predictably) although the GET header needs to NOT have the colon after it.
Token = 6d40c7d26a94c56b4b1ee001318bb7d7; "GET /path_1/path_2/websocket" = ""; "CountryCode" = GB;

Is there any way I can modify StompKit to do this?

James

jmesnil commented 10 years ago

StompKit does not work over WebSocket. You should connect to the STOMP broker on its stomp port (usually 61613), not over a Web Socket on the 80 port.

jodm commented 10 years ago

Hi.

Thanks for the quick reply.

We are using STOMP over web sockets (Port 80). I can't seem to find any frameworks to support this? Is there any way of getting STOMPKit to work like this?

Can I do a standard web socket connection and pass this connection to StompKit?

The Javascript / Frontend guys are connecting to STOMPKit this:

(function () {
    var socket = new SockJS('http://www.url.com/path_1/stomp');
    var stompClient = Stomp.over(socket);

    stompClient.connect('', '', function (frame) {
        console.log('Connected ' + frame);

        stompClient.subscribe("/topic/1", function (message) {
            console.log(message.body);
        });
    }, function (error) {
        console.log("STOMP protocol error " + error);
    });
})();

Thanks James

jmesnil commented 10 years ago

Like I said, StompKit can connect to the STOMP broker on a regular TCP port. Which broker are you using?

the stomp.js JavaScript library you are using is connecting over a Web Socket because you have no choice from a Web browser. But from an Objective-C client, there is no such restriction and you can connect to the TCP port directly.

masgharneya commented 10 years ago

@jodm StompKit is well written and won't require many changes to get your messages to go over websockets. You will need to replace GCDAsyncSocket with a web socket client. The only complete iOS one I know of is SocketRocket.

jodm commented 10 years ago

@masgharneya I finally got it working but thank you for your advise.

I used SocketRocket to do the websocket connection and then wrote my own STOMP message framework. For anyone interested I am planning on releasing this as a library:

https://github.com/jodm/SocketStompRocket

It will be uploaded by the end of March I just need to finish the iPhone application I am working on and I will extract it and make it standalone.

Sumitkashid commented 9 years ago

@jodm I want to know whether you have updated SocketStompRocket library on any other repository location? Because https://github.com/jodm/SocketStompRocket location do not have any other file except README.md file.

gandhrekunal commented 9 years ago

Hi @jodm , even I required SocketStompRocket library, can you please share repository location.

jodm commented 9 years ago

Hi. @Sumitkashid @gandhrekunal You know what it's like, best intensions to extract code from a project into a separate library and never get a chance.

I will try and find some time this week and extract it and update the SocketStompRocket repository.

Edit: One thing to note is I no longer have access to the Stomp / Socket Server so I won't be able to fully test but the code was working when the server was live.

Thanks James.

tbowers commented 9 years ago

I have an outstanding pull request to integrate this functionality using RocketSockets. It seems to be working except the heartbeating (receiving PONG from my server) isn't working. I'm not sure which end is at fault yet.

masgharneya commented 9 years ago

@tbowers your PR will remove StompKit's ability to work over plain sockets. Might make more sense as a separate project.

tbowers commented 9 years ago

@masgharneya could you elaborate how? I specifically implemented the strategy pattern so that the existing raw socket usage would still work. If you init with a host that starts w/ "ws://", it'll use web sockets. If you init with host and port (i.e. existing API), the raw socket will be used.

masgharneya commented 9 years ago

@tbowers my mistake. I looked at one of the files you changed and saw that you removed a GCDAsyncSocket import so I assumed you removed it from the project. I should have looked further.

lifeng198931 commented 8 years ago

Hi, I use stompkit to connect rabbitmq server , but i don't know how to use the vhost parameter,i want to know how to use the vhost parameter? thank you!

buffpojken commented 8 years ago

@lifeng198931 Your question has no relation to this issue at all, please open a new issue if you have specific questions.

Otherwise - see https://www.rabbitmq.com/access-control.html for a discussion on vhosts (which also really has nothing to do with STOMP per se but is up to every specific broker to implement.