Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client feature request: add WebSocket support #69

Open
kanaka opened this issue Jul 5, 2013 · 16 comments
Open

Client feature request: add WebSocket support #69

kanaka opened this issue Jul 5, 2013 · 16 comments

Comments

@kanaka
Copy link

kanaka commented Jul 5, 2013

It would be nice to be able to use one library for both WebSocket servers and clients. It looks like currently only creating WebSocket servers is supported by http-kit.

@shenfeng
Copy link
Member

shenfeng commented Jul 5, 2013

I'd love to add websocket clent support too. I've try it, the only thing that prevent me from doing is: I can not think of a Good enough API. Can you please help by providing the ideal way you want to use http-kit.

@clifton
Copy link

clifton commented Jul 11, 2013

I'm looking for something similar as well, however websockets have pretty poor cross-browser support right now.

https://github.com/sockjs/sockjs-client seems to be a good solution for streaming and push-based services that need cross-browser support, but the only JVM-compatible server implementation of the protocol is vertx.

It would be really neat if there was a sockjs implementation built off of http-kit, and even nicer if core.async could be utilized.

@kanaka
Copy link
Author

kanaka commented Jul 24, 2013

@shenfeng I'm not sure what an ideal interface would be, but at a minimum it could like like a combination of normal browser API (http://www.w3.org/TR/2011/WD-websockets-20110929/#handler-websocket-onopen) and clj-http request API. Something like this:

(:require [org.httpkit.client :as client])

(let [protocols ['my-prot-1' 'my-prot-2']
      ws (client/websocket "ws://host:port/path" 
           :protocols protocols
           :headers {}
           :on-open (fn []
                       (println "connected"))
           :on-close (fn [code reason clean?]
                       (println "closed" code reason))
           :on-receive (fn [data]
                         (println "got data:" data)))
  (client/send! ws "my message")
  (client/close! ws 1006 "normal exit"))

It might also be useful if the returned object had additional protocols that allow runtime settings to be queried (readyState, bufferedAmount) and changed (on-open, on-close, on-receive, etc).

@cgmartin
Copy link

👍 for @kanaka 's interface suggestion. Might also pass in the ws reference to the on-open & on-receive callbacks for use of send!/close! fns.

@shenfeng
Copy link
Member

Hi, @kanaka @cgmartin , Thanks for suggestion.

I will try to write some code, make it working, then we can experiment it, design the interface. I'd like to provide a clean and easy to use API.

@myguidingstar-zz
Copy link

@eneroth
Copy link

eneroth commented Dec 17, 2013

James Henderson has a solution that wraps http-kit websocket communication in core.async channels. As far as an API semantics goes, I don't think we're going to get anything better than channels to describe communication over, indeed, a channel. However, as previously pointed out, browser support remains remains a question mark. Supported from IE 10 and not supported on Android at all?

@kanaka
Copy link
Author

kanaka commented Dec 17, 2013

@eneroth Modern versions of Android default to Chrome for Android which has WebSocket support. Older versions of IE (6-9) and some Android installs can support WebSockets using the web-socket-js Flash shim. You don't get binary data support with the shim, but those platforms don't have binary data (typed arrays and blobs) anyways. That means the supported marketshare for basic WebSocket support is actually quite high.

@eneroth
Copy link

eneroth commented Dec 17, 2013

@kanaka That's pretty good news! But I'd be digging a hole for myself if I tried sending Fressian over the socket then? (given the state of binary support)

@kanaka
Copy link
Author

kanaka commented Dec 17, 2013

@eneroth if you are already dealing with fressian data in browsers that don't have native binary types, then that means you have some sort of way of representing/storing it in those browser's existing data types (binary coded string, regular array of bytes, etc). You may just need to base64 encode what you already have and then base64 decode on the other end. You would lose some of the efficiency of fressian, but it might be enough for what you are trying to do.

@txrev319
Copy link

What is the current state of this? :-)

@shenfeng
Copy link
Member

Hi, I'am not sure the time schedule for http-kit has support for websocket client.

There is another one that's maybe useful: https://github.com/neotyk/http.async.client
I've used it to do the unit test https://github.com/http-kit/http-kit/blob/master/test/org/httpkit/ws_test.clj#L197

@txrev319
Copy link

I understand you want to (1) get the right API rather than (2) release something hacky and ahve to change the API later.

Thanks for the references!

@ptaoussanis ptaoussanis changed the title websocket client support Client feature request: add WebSocket support Dec 13, 2015
@ptaoussanis
Copy link
Member

Ref. #101 for API discussion

@TRManderson
Copy link

Hey, this feature request has no updates since 2015 - just wondering what the current state of websocket client support is. Is it implemented and just not documented yet?

@ptaoussanis
Copy link
Member

Hi @TRManderson, unfortunately no updates since last updates on this thread.
To get this moving, someone interested would need to provide a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants