Domanda

I have mnesia DB with table artists:

(gw@gw)227> lookup:for_test().
{atomic,["Baltic Baroque","Anna Luca","Karel Boehlee Trio",
     "Bill Evans","Dino Saluzzi and  Anja Lechner",
     "Bill Evans Trio with Stan Getz","Duke Pearson",
     "The John Butler Trio"]}
(gw@gw)228>

I want send this list to client by websocket in YAWS, but how i can do it? I broke my mind ... and nothing working. Please help by any info.

Best regards!

È stato utile?

Soluzione

You have to convert this list of string to binaries and the pass is across over web socket, by the way what kind of data handling are you doing at the receiving end I mean you want to send this as JSON or just Comma separated values?

Altri suggerimenti

Yeeeees ... i solve my problem! My YAWS Handle

handle_message({text, <<"q2">>}) ->
Var555 = unicode:characters_to_binary(my_json4:handle()),
{reply, {text, <<Var555/binary>>}};

And my mnesia select + convert to JSON. my_json4.erl

Data = [{obj,
         [{art_id, Line#tmp.artist_id},
          {art,    unicode:characters_to_binary(Line#tmp.artist)},
          {alb_id, Line#tmp.album_id},
          {alb,    unicode:characters_to_binary(Line#tmp.album)},
          {path,   unicode:characters_to_binary(Line#tmp.albumpath)},
          {image,  unicode:characters_to_binary(Line#tmp.image)},
          {tracks, [unicode:characters_to_binary(X) ||X <- Line#tmp.tracks]}]}
        || Line <- Lines],
JsonData = {obj, [{data, Data}]},
rfc4627:encode(JsonData).

handle() ->
 QHandle = qlc:q( [ X ||
   X <- mnesia:table(artists),
   X#artists.artist_id == 2]
 ),
 Records = do(qlc:q([{tmp, X#artists.artist_id, X#artists.artist, A#albums.album_id, A#albums.album, A#albums.albumpath, A#albums.image, A#albums.tracklist} ||
    X <- QHandle,
    A <- mnesia:table(albums),
    A#albums.artist_id == X#artists.artist_id])
),
Json = convert_to_json(Records),
Json.


do(Q) ->
F = fun() ->
            qlc:e(Q)
    end,
{atomic, Value} = mnesia:transaction(F),
Value.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top