aleph

eslachance 2017-02-01T03:59:26.000036Z

Alright. Thankfully someone can help me out before I pull my hair out. I have this very odd issue. I'm using aleph/manifold to connect to a websocket, and s/consume doesn't seem to be triggering at all and I really don't know why. Evaluating each relevant line one at a time works from the repl, just not within a function. Here's the exact line that doesn't trigger: https://github.com/eslachance/dithcord/blob/master/src/dithcord/core.clj#L121

dm3 2017-02-01T06:33:41.000039Z

what's the manifold version?

eslachance 2017-02-01T08:38:47.000040Z

@dm3 I just have [aleph "0.4.1"]

dm3 2017-02-01T11:48:26.000041Z

@eslachance what does printing the stream that you consume show?

dm3 2017-02-01T11:48:45.000042Z

e.g.

boot.user=> (manifold.stream/stream)
<< stream: {:pending-puts 0, :drained? false, :buffer-size 0, :permanent? false, :type "manifold", :sink? true, :closed? false, :pending-takes 0, :buffer-capacity 0, :source? true} >>

dm3 2017-02-01T11:49:36.000043Z

after you start consuming the stream, it should have a :pending-takes 1 and :closed? should be false

dm3 2017-02-01T11:49:44.000044Z

and :drained? should also be false

eslachance 2017-02-01T11:53:12.000045Z

When I call that function (ws-connect) it returns the session, which has the stream as a socket

eslachance 2017-02-01T11:53:29.000046Z

and printing out (:socket @session) does show that stream

dm3 2017-02-01T11:53:37.000047Z

ws is the stream you're consuming

eslachance 2017-02-01T11:53:54.000048Z

yes which I have as (swap! session assoc :socket ws)

eslachance 2017-02-01T11:53:58.000049Z

let me see about drained

dm3 2017-02-01T11:55:23.000050Z

what happens if you just do

(let [x @(http/websocket-client "<wss://gateway.discord.gg/v?6&amp;encoding=json>")]
  (s/consume #(println "DEBUG" %) x))
?

eslachance 2017-02-01T11:55:57.000051Z

.... nothing

eslachance 2017-02-01T11:56:04.000052Z

well sorry it returns nil to be precise

dm3 2017-02-01T11:56:19.000053Z

yes

dm3 2017-02-01T11:56:32.000054Z

which means you are not receiving anything on that URL?

eslachance 2017-02-01T11:56:34.000055Z

nothing else, no message, not output.

dm3 2017-02-01T11:56:42.000056Z

what if you try another WS client?

eslachance 2017-02-01T11:56:58.000059Z

But I am though if I do

(def conn @(http/websocket-client "<wss://gateway.discord.gg/?v=6&amp;encoding=json>"))
(s/on-closed conn (fn [] (prn "closed")))
(s/consume (fn [msg] (prn msg)) conn) 
then I do get a message

eslachance 2017-02-01T11:57:26.000060Z

I get a first packet, and then I get a closed message after a second or so because the websocket is expecting an identity packet

eslachance 2017-02-01T11:57:33.000061Z

which, if I provide it, does work

eslachance 2017-02-01T11:57:43.000062Z

So I'm receiving packets fine when I def the connection. But when I use let it doesn't work

dm3 2017-02-01T11:58:09.000063Z

that doesn't affect anything

eslachance 2017-02-01T11:58:27.000064Z

I was previously using http.async.client , which worked fine except for the fact that it crashes the websocket on large packets (a bug in the java lib it uses)

dm3 2017-02-01T11:58:49.000065Z

so you have some code using aleph that works?

eslachance 2017-02-01T11:59:01.000066Z

I do. those 3 lines work

eslachance 2017-02-01T11:59:23.000068Z

That's the packet

dm3 2017-02-01T11:59:33.000069Z

and you are saying that

(let [conn @(http/websocket-client "<wss://gateway.discord.gg/?v=6&amp;encoding=json>"))]
  (s/on-closed conn (fn [] (prn "closed")))
  (s/consume (fn [msg] (prn msg)) conn))
doesn't?

eslachance 2017-02-01T12:00:13.000070Z

hmm

eslachance 2017-02-01T12:00:22.000071Z

wait a sec. no it does.

eslachance 2017-02-01T12:00:25.000072Z

...

eslachance 2017-02-01T12:00:53.000073Z

but...

(let [x @(http/websocket-client "<wss://gateway.discord.gg/v?6&amp;encoding=json>")]
  (s/consume #(println "DEBUG" %) x)) 
didn't work. IT didn't print out that packet

eslachance 2017-02-01T12:01:07.000074Z

the heck?

dm3 2017-02-01T12:01:15.000075Z

maybe there was no packet?

dm3 2017-02-01T12:01:22.000076Z

try looking with wireshark or something?

eslachance 2017-02-01T12:01:32.000077Z

I don't even know what that is >.<

eslachance 2017-02-01T12:01:38.000078Z

but really I know this API

eslachance 2017-02-01T12:01:45.000079Z

we're talkinga bout Discord here it always sends a packet

eslachance 2017-02-01T12:01:53.000080Z

consistently

dm3 2017-02-01T12:01:58.000081Z

the URL is wrong

eslachance 2017-02-01T12:02:13.000082Z

OH MY GOD

eslachance 2017-02-01T12:02:24.000083Z

...

eslachance 2017-02-01T12:02:26.000084Z

Thank you.

eslachance 2017-02-01T12:02:34.000085Z

I shall take my shame and go fix the error

dm3 2017-02-01T12:02:44.000086Z

happens πŸ™‚

eslachance 2017-02-01T12:04:19.000087Z

Obviously, this does bring to light that aleph doesn't have an "on-error" event cough

eslachance 2017-02-01T12:04:27.000088Z

(well manifold doesn't?)

dm3 2017-02-01T12:11:15.000089Z

it's probably closing the stream, no?

dm3 2017-02-01T12:11:41.000090Z

and there's https://github.com/ztellman/manifold/issues/95

dm3 2017-02-01T12:11:48.000092Z

which has no definite answer

eslachance 2017-02-01T12:13:54.000093Z

True, but when a websocket closes, it has a reason to close. Getting that reason would be... useful.

dm3 2017-02-01T12:15:03.000094Z

agree

eslachance 2017-02-01T12:16:11.000095Z

I mean we have s/on-close why not s/on-error. I feel that's expected, and consistent.

eslachance 2017-02-01T12:16:21.000096Z

And also consistent with other libraries

dm3 2017-02-01T12:16:48.000097Z

you can contribute to the issue above

dm3 2017-02-01T12:16:58.000098Z

all thoughts welcome πŸ™‚

eslachance 2017-02-01T12:24:53.000099Z

Obviously!

eslachance 2017-02-01T12:25:17.000100Z

Once I get this all working I'm planning a series of video tutorials on various things clojure-related in the shape of a development story for my library

eslachance 2017-02-01T12:25:55.000101Z

But that's once I get it working ^_^

eslachance 2017-02-01T12:46:10.000102Z

Any way to handle a zlib compressed packet? It shows up as #object["[B" 0x7282913c "[B@7282913c"] if I just print it to console, not exactly sure how to handle that

dm3 2017-02-01T12:48:30.000103Z

I guess you need to decompress it yourself

eslachance 2017-02-01T12:51:02.000105Z

And the java interop adventure beings....

eslachance 2017-02-01T13:10:13.000108Z

Wait what about byte-streams?

eslachance 2017-02-01T13:10:31.000109Z

ooooh

eslachance 2017-02-01T13:12:55.000110Z

I feel like I'm so close though

"x?????0\fE??k???]?????A?t\"??K??\b??e2???vG?G???\n\rz??????B/;X/?&amp;??\n??`??\r?Z???????z ??9?m??_?L??;?S??*8.??(?c4!8%????0?1/?}Y?B?i??\\???BY????E??\r?f??)i\fΒΊ?Z??$??u??+??2&lt;?\r?B&amp;\"5?1LIz?!*?Iz??,?l?`???/?????Y??t?Rh??R????y??2??+????????NGa???\r??R8?u??\b+c????*\n???k????ab??q?u?G??.\\?4?}??U?f?r???l?r"
 

eslachance 2017-02-01T23:14:02.000112Z

Oh btw, @dm3 that approach did work, I included it in my project, and used the following line on the incoming packet:

(String. (byte-array (z/inflate msg))) 
(z/ being that zip.clj file)

eslachance 2017-02-01T23:15:48.000113Z

Took a lot of mucking around and some help from other people but it works!