<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 24, 2017 at 1:53 AM, Gattu shiva krishna <span dir="ltr"><<a href="mailto:gattushivakrishna@utl.in" target="_blank">gattushivakrishna@utl.in</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  
    
  
  <div 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></div></blockquote><div><br></div><div>As Jesper already explained, what the client will receive in this case is the equivalent of</div><div><br></div><div><<"data:button1button2\n">></div><div><br></div><div>Is that really what you're trying to send? Parsing that seems difficult.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#FFFFFF">
    <p>        when i'm trying to send this data to client side using
      below function <br>
    </p>
            yaws_sse:send_events(A#arg.<wbr>clisock, Data)<br>
    <br>
            but in client side iam unable to retrieve the data, Is there
    any solution for this.<br>
    <br>
------------------------------<wbr>------------------------------<wbr>------------------------------<wbr>------------------------------<wbr>----------------------<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>
                                  <wbr>   [[<<"data:">>,<br>
                                  <wbr>     [ "button1", "button2" ],<br>
                                  <wbr>     <<"\n">>],<br>
                                  <wbr>    <<"\n">>])
    (gen_tcp.erl, line 261)<span class="gmail-"><br>
    <br>
        What is the format of arguments that need to be given to this
    function.<br></span></div></blockquote><div><br></div><div>You're getting this error because you're passing the port argument as an atom, not as a port. Assuming you're using a relatively recent version of Erlang/OTP, in the shell the port you've mentioned should be specified as</div><div><br></div><div>#Port<0.3333></div><div><br></div><div>without quotes. The whole call becomes</div><div><br></div><div>yaws_sse:send_events(#Port<0.3333>, [<<"data:">>,[ "button1", "button2" ],<<"\n">>]).</div><div><br></div><div>or more simply but equivalently</div><div><br></div><div>yaws_sse:send_events(#Port<0.3333>, <<"data:button1button2\n">>).<br></div><div><br></div><div>which will send the data you specify, assuming #Port<0.3333> is really the right connection. But again, the data you're sending is poorly structured and so won't be easy for your client to deal with.</div><div><br></div><div>--steve</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#FFFFFF"><span class="gmail-">
    <br>
    </span><div><div class="gmail-h5"><div class="gmail-m_-8245671621134646903moz-cite-prefix">On Wednesday 23 August 2017 04:08 PM,
      Jesper Louis Andersen wrote:<br>
    </div>
    <blockquote type="cite">
      <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" target="_blank">http://prog21.dadgum.com/70.<wbr>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" target="_blank">gattushivakrishna@utl.in</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);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.<wbr>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>
------------------------------<wbr>------------------------------<wbr>------------------------------<wbr>------------------------------<wbr>---------------<br>
          <br>
          SERVER SIDE CODE:<br>
          <br>
            <erl><br>
                   out(A) -><br>
                       Data = yaws_sse:data(["Button1",<br>
          "Button2","Button3","Button4"]<wbr>),<br>
          <br>
                       yaws_sse:send_events(A#arg.<wbr>clisock, Data).<br>
               </erl><br>
          <br>
------------------------------<wbr>------------------------------<wbr>------------------------------<wbr>------------------------------<wbr>---------------<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,<wbr>buttonContainer,
          newButton;<br>
          <br>
                   buttonsToCreate = event.data;<br>
                       buttonContainer =<br>
          document.getElementById('this_<wbr>element_contains_my_buttons');<br>
                   for (i = 0; i <= buttonsToCreate.length ; i++)<br>
                   {<br>
                         newButton = document.createElement('input'<wbr>);<br>
                         newButton.type = 'button';<br>
                         newButton.value = buttonsToCreate[i];<br>
                         newButton.id = buttonsToCreate[i];<br>
                         buttonContainer.appendChild(<wbr>newButton);<br>
                   }<br>
               };<br>
          <br>
               </script><br>
          <br>
          ______________________________<wbr>_________________<br>
          erlang-questions mailing list<br>
          <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
          <a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
        </blockquote>
      </div>
    </blockquote>
    <br>
  </div></div></div>

<br>______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div></div>