Re: [racket-users] Proxying websockets via web-server

2020-01-14 Thread Eli Barzilay
On Tue, Jan 14, 2020 at 8:09 PM Jay McCarthy  wrote:
>
> As far as examples, there are some in the github repository ---
> https://github.com/tonyg/racket-rfc6455/tree/master/net/rfc6455/examples

Yeah, I saw them, but they're all examples of just starting a
websocket server.  What's missing (and it's not even clear to me if
it's possible without tweaking the library code) is some example that
shows what Dominick asked: serving some pages together with a
websocket.  This is something that I suspect is the much more common
case than starting just a websocket-only server.  (And I basically
"solved" it by starting another webserver on a different subdomain
just for this.)

-- 
   ((x=>x(x))(x=>x(x)))  Eli Barzilay:
   http://barzilay.org/  Maze is Life!

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CALO-guvz_sXrMR9czAYCNBzJ8urrL7qO-gBPBd%2BoybOo-4hdgg%40mail.gmail.com.


Re: [racket-users] Proxying websockets via web-server

2020-01-14 Thread Jay McCarthy
Hi Dominik,

The cited package is definitely what you want, but you'll have to
crack open the source code a little bit to access the underlying
pieces. It currently uses all of the existing `web-server` libraries
and sets up a dispatcher chain for Websockets. You can see the entry
point here --- 
https://github.com/tonyg/racket-rfc6455/blob/master/net/rfc6455/server.rkt#L46
and 
https://github.com/tonyg/racket-rfc6455/blob/master/net/rfc6455/dispatcher.rkt#L9
--- so I think you just need to customize those things and attach them
to your own dispatcher chain.

Jay

--
Jay McCarthy
Associate Professor @ CS @ UMass Lowell
http://jeapostrophe.github.io
Vincit qui se vincit.

On Sun, Jan 12, 2020 at 11:18 AM Dominik Pantůček
 wrote:
>
> Sigh... I forgot to reply to the list... Here we go:
>
> I want a single HTTP server like serve/servlet (or similar) that handles
> all requests by the standard dispatcher/c logic - ideally using
> dispatch/servlet with dispatch-case to specify the mapping. And for one
> specific URL path "/sockjs-node", I need it to be able to do the
> websocket HTTP 101 protocol switch.
>
> The React.js application in the browser just communicates using HTTP and
> if you run its minimal node.js server with "npm start" its HTTP
> implementation contains the selective websocket URL path and it works. I
> just need a way to proxy this, as my Racket backend is the HTTP server.
> For static data I produce response/full with that data, for API calls,
> it is response/jsexpr and for this websocket endpoint, I would like to
> run copy-port and be done with it - after the protocol switch, that is.
>
> From what I read about rfc6455 package, it cannot be used with the
> web-server package. I'll dive into the source later today.
>
> Actually I can live without that, yet I was curious as it provides a
> convenient way to reload the frontend after source changes in its code
> (that is the Javascript part). For production builds, a plain
> serve/servlet does all the job required.
>
>
> Dominik
>
> On 11. 01. 20 3:18, Jay McCarthy wrote:
> > I don't completely understand what you want to do. Is there a reason
> > you can't use the WebSocket implementation ---
> > https://docs.racket-lang.org/rfc6455/index.html --- and then use
> > normal inter-Racket communication like channels and stuff to work with
> > the rest of your Web application?
> >
> > Jay
> >
> > --
> > Jay McCarthy
> > Associate Professor @ CS @ UMass Lowell
> > http://jeapostrophe.github.io
> > Vincit qui se vincit.
> >
> > On Thu, Jan 9, 2020 at 5:23 PM Dominik Pantůček
> >  wrote:
> >>
> >> Hello everyone,
> >>
> >> I am working on an application that uses React.js[1] for front-end and
> >> Racket as HTTP back-end server.
> >>
> >> For production builds, the Javascript part is compiled using "npm build"
> >> which generates a directory full of HTML and Javascript files which are
> >> then included in the Racket application during syntax stage as an
> >> immutable hash. For development builds, the Racket application runs "npm
> >> start" in the front-end source directory and proxies all non-backend
> >> requests to the managed node.js server.
> >>
> >> When run in the development setup (that is with the node.js secondary
> >> HTTP server), the proxying using serve/servlet and simple dispatch-case
> >> works like a charm - each servlet uses http-sendrecv to get the data
> >> from the secondary HTTP server and returns it as appropriate response body.
> >>
> >> But the reason for this setup is that React.js can automatically reload
> >> the webpage, if any of the source files change. To do this trick, it
> >> uses an url "/sockjs-node". The browser sends GET request for this
> >> resource and the node.js server responds with "HTTP/1.1 101 Switching
> >> Protocols" like in [2].
> >>
> >> Apparently, to make this work, I need to establish a bi-directional
> >> connection after the 101 response code. This is impossible with
> >> serve/servlet. I have done some experiments with plain (serve #:dispatch
> >> ...) and just cannot make it work all at once. With connection-i-port
> >> and connection-o-port it should be (relatively) easy to implement. But
> >> the documentation is virtually nonexistent and browsing the
> >> web-server/private/ sources is a bit tricky if I do not know what I am
> >> looking for.
> >>
> >> If anyone can give me a hint how a proper setup for websocket
> >> implementation should look like, I would really appreciate it. Of
> >> course, I also want to use the dispatch-case with plain requests as it
> >> automates most of the real work I need to perform there.
> >>
> >>
> >>
> >> Cheers,
> >> Dominik
> >>
> >> [1] https://reactjs.org/
> >> [2] https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake
> >>
> >> --
> >> You received this message because you are subscribed to the Google Groups 
> >> "Racket Users" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an 
> >> email to 

Re: [racket-users] Proxying websockets via web-server

2020-01-14 Thread Jay McCarthy
Thanks for noticing that problem with the format string, Eli.

As far as examples, there are some in the github repository ---
https://github.com/tonyg/racket-rfc6455/tree/master/net/rfc6455/examples

--
Jay McCarthy
Associate Professor @ CS @ UMass Lowell
http://jeapostrophe.github.io
Vincit qui se vincit.

On Sat, Jan 11, 2020 at 11:17 PM Eli Barzilay  wrote:
>
> On Fri, Jan 10, 2020 at 9:18 PM Jay McCarthy  wrote:
> >
> > I don't completely understand what you want to do. Is there a reason
> > you can't use the WebSocket implementation ---
> > https://docs.racket-lang.org/rfc6455/index.html --- and then use
> > normal inter-Racket communication like channels and stuff to work with
> > the rest of your Web application?
>
> It would be nice if the documentation for that would have some
> examples, but after playing with it for a bit it looks like it's
> broken, possibly because I don't use it properly.  I keep getting
> errors that look like "read-request: malformed request ..." with
> binary goo in the error message, which usually displayed like random
> unicode, sometimes it breaks the terminal due to weird escape
> sequences.  Even if I'm not using it properly, such errors shouldn't
> happen.
>
> And as a side note, one of the errors I saw was:
>
>  exception raised by error display handler: format: ill-formed pattern string
>explanation: tag `~l' not allowed
>pattern string: "read-request: malformed request
> ...junk...~l...more..."; original exception raised: read-request: ...
>
> which looks like a bad error re-raising in the web server code.  A
> quick grep finds at least one suspicious line which erroneously uses a
> random string as a format string:
>
> (with-handlers ([exn:fail? (lambda (exn) (network-error
> 'output-file (exn-message exn)))]) ...
>
> --
>((x=>x(x))(x=>x(x)))  Eli Barzilay:
>http://barzilay.org/  Maze is Life!

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAJYbDa%3DvL%3D8EZfKdAPWFV8vmxwGOL7TCaHo8Ofpx1XYja8ZRRg%40mail.gmail.com.


Re: [racket-users] Surprising behavior in The Printer

2020-01-14 Thread Matthew Flatt
The short answer is that you're right: creating new values at
custom-print time creates trouble for graph detection and `print`
quoting. Those operations perform a pass to make decisions about graphs
and quoting based on `eq?` identity, and then they make another pass to
actually print. I'll update the documentation to clarify.

A longer answer is that your example and variations expose several
mismatches between the `racket/pretty` printer, the built-in printer
for current Racket, and the built-in printer for Racket CS. I'm working
on changes and tests to make them more consistent, but the changes
don't produce the result you wanted. If you put `maybe-rebuild` in
`custom-print`, then they more consistently produce the output that you
don't want.

Of course, an even better improvement would collapse the three
different implementations of the printer. One day, we may be able to
use the Racket CS I/O layer in place of the implementation in current
Racket, and then folding in pretty-print support may become practical.

At Fri, 10 Jan 2020 16:58:34 -0800 (PST), Ryan Kramer wrote:
> I have a small program that demonstrates some surprising behavior regarding 
> `prop:custom-print-quotable 'never`. Perhaps it could be considered a bug, 
> although I haven't seen anything in the docs that this violates. I've found 
> that
> 
> 1. When I call `(println y)`, my `custom-display` is called first. And what 
> I do in `custom-display` affects the result of `(println y)`
> 2. The printer is doing something with `eq?` rather than `equal?`. (Does 
> this mean that constructing any new data structure, even a list, during 
> printing is an anti-pattern?)
> 
> In the example below, if `(maybe-rebuild lst)` returns `(identity lst)` 
> then `prop:custom-print-quotable 'never` works as I expected. But if 
> `(maybe-rebuild lst)` returns `(apply list lst)` which is a list that is 
> equal? but not eq? to the original list, then `prop:custom-print-quotable 
> 'never` surprises me.
> 
> #lang racket
> 
> (require racket/struct)
> 
> (struct my-struct (item) #:transparent
>   #:property prop:custom-print-quotable 'never)
> 
> (define (go port mode val)
>   (let ([proc (make-constructor-style-printer
>(λ (me) 'my-class%)
>(λ (me) (list val)))])
> (proc (void) port mode)))
> 
> (define (maybe-rebuild lst)
>   ; Works as expected if we return the same list
>   #;(identity lst)
>   ; But this breaks prop:custom-print-quotable 'never
>   (apply list lst))
> 
> (define my-class%
>   (class* object% (printable<%>)
> (super-new)
> (init-field content)
> (define/public (custom-print port mode)
>   (go port mode content))
> (define/public (custom-write port)
>   (go port #t content))
> (define/public (custom-display port)
>   (go port #f (maybe-rebuild content)
> 
> (define x (list 'CONTENT (my-struct '(1 a
> (println x)
> (define y (new my-class% [content x]))
> (println y)

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/20200114203624.76CA8650189%40mail-svr1.cs.utah.edu.