<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>Hi,</p>
    <p>        when i'm using below function <br>
    </p>
    <p>        Data = yaws_sse:data( [ "button1", "button2" ] ),</p>
    <p>        the result value of that function is  <br>
    </p>
    <p>        [<<"data:">>, [ "button1", "button2" ],
      <<"\n">>]</p>
    <p>        when i'm trying to send this data to client side using
      below function <br>
    </p>
            yaws_sse:send_events(A#arg.clisock, Data)<br>
    <br>
            but in client side iam unable to retrieve the data, Is there
    any solution for this.<br>
    <br>
----------------------------------------------------------------------------------------------------------------------------------------------<br>
    <br>
            when i'm trying to use this  function (
    yaws_sse:send_events/2 )manually in yaws shell.<br>
    <br>
            for example :<br>
    <br>
            1> yaws_sse:send_events( '#port<0.3333>',
    [<<"data:">>,[ "button1", "button2"
    ],<<"\n">>]).<br>
     <br>
            It is giving some error like this :<br>
            <br>
            ** exception error: no function clause matching <br>
                        gen_tcp:send('#port<0.3333>',<br>
                                     [[<<"data:">>,<br>
                                       [ "button1", "button2" ],<br>
                                       <<"\n">>],<br>
                                      <<"\n">>])
    (gen_tcp.erl, line 261)<br>
    <br>
        What is the format of arguments that need to be given to this
    function.<br>
    <br>
    <div class="moz-cite-prefix">On Wednesday 23 August 2017 04:08 PM,
      Jesper Louis Andersen wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAGrdgiWHVcmjnMtRnbsVjHmNJUNcF84UJB0TntywCOnYgTPa3A@mail.gmail.com">
      <div dir="ltr">
        <div>
          <div>
            <div>
              <div>
                <div>
                  <div>
                    <div>
                      <div>
                        <div>
                          <div>Here is what I think is going wrong,
                            though I'm not entirely sure:<br>
                            <br>
                          </div>
                          The Yaws yaws_sse:data/1,2 functions assume
                          the data you give them are so-called iodata().
                          So when you write something like<br>
                          <br>
                        </div>
                        ["Button1", "Button2"]<br>
                        <br>
                      </div>
                      and send it, it is effectively flattened into a
                      binary<br>
                      <br>
                    </div>
                    <<"Button1Button2">><br>
                    <br>
                  </div>
                  The iodata() system is really nice for doing
                  scatter/gatter (typo intended) IO, but you have to
                  invent some kind of framing in which you run.<br>
                  <br>
                </div>
                For example, we could use JSON:<br>
                <br>
              </div>
              X = [<<"Button1">>,
              <<"Button"2>>],<br>
            </div>
            Data = yaws_sse:data(jsx:encode(X)),<br>
            ...<br>
            <br>
          </div>
          which encodes the data into a JSON structure which we can
          handle on the client side.<br>
          <br>
        </div>
        Also, look up the iodata() concept. It is pretty nice. There is
        an old post by James Hague on it:<br>
        <br>
        <a href="http://prog21.dadgum.com/70.html"
          moz-do-not-send="true">http://prog21.dadgum.com/70.html</a><br>
        <br>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr">On Wed, Aug 23, 2017 at 12:27 PM Gattu shiva
          krishna <<a href="mailto:gattushivakrishna@utl.in"
            moz-do-not-send="true">gattushivakrishna@utl.in</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
          <br>
                   I'm learning to use yaws web-server and I came across
          server<br>
          sent events which is used to send data to the client. To send
          data to<br>
          the client I'm using the function
          yaws_sse:send_events(A#arg.clisock,<br>
          Data). What is the format of arguments that need to be given
          to this<br>
          function. I've googled enough and didn't get any satisfactory
          results.<br>
          Below is a sample application where I'm trying to experiment
          on<br>
          server-sent-events.<br>
          <br>
               Here in code I'm trying to create buttons dynamically in
          client<br>
          side based on data that comes from server side.<br>
          <br>
---------------------------------------------------------------------------------------------------------------------------------------<br>
          <br>
          SERVER SIDE CODE:<br>
          <br>
            <erl><br>
                   out(A) -><br>
                       Data = yaws_sse:data(["Button1",<br>
          "Button2","Button3","Button4"]),<br>
          <br>
                       yaws_sse:send_events(A#arg.clisock, Data).<br>
               </erl><br>
          <br>
---------------------------------------------------------------------------------------------------------------------------------------<br>
          <br>
          CLIENT SIDE CODE:<br>
          <br>
          <script type="text/javascript"><br>
                 var source = new EventSource("button.yaws");<br>
                 source.onmessage = function(event) {<br>
                       var i, buttonsToCreate,buttonContainer,
          newButton;<br>
          <br>
                   buttonsToCreate = event.data;<br>
                       buttonContainer =<br>
          document.getElementById('this_element_contains_my_buttons');<br>
                   for (i = 0; i <= buttonsToCreate.length ; i++)<br>
                   {<br>
                         newButton = document.createElement('input');<br>
                         newButton.type = 'button';<br>
                         newButton.value = buttonsToCreate[i];<br>
                         newButton.id = buttonsToCreate[i];<br>
                         buttonContainer.appendChild(newButton);<br>
                   }<br>
               };<br>
          <br>
               </script><br>
          <br>
          _______________________________________________<br>
          erlang-questions mailing list<br>
          <a href="mailto:erlang-questions@erlang.org" target="_blank"
            moz-do-not-send="true">erlang-questions@erlang.org</a><br>
          <a href="http://erlang.org/mailman/listinfo/erlang-questions"
            rel="noreferrer" target="_blank" moz-do-not-send="true">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
        </blockquote>
      </div>
    </blockquote>
    <br>
  </body>
</html>