How to send and get data from the server using Ratchet
<p>This is the first time I am using sockets and started off with <strong>Ratchet</strong> but I seriously cant fit my head into it. Still tried to join together some parts from the tutorial but facing some problems. Plus I would like to know how to use <strong>autobahn.js</strong> with it. The tutorials are not clear.</p>

<p><strong>My Problem</strong></p>

<p>1)   How to send a message to all users except the current user stating "
      ... joined" and the '...' has to be the ip of the user.</p>

<p>I tried the following but it gives me error on the terminal.</p>

<pre><code>public function onOpen(ConnectionInterface $conn) {
           // Store the new connection to send messages to later
           $this-&gt;clients-&gt;attach($conn);
           $this-&gt;send('new');
           echo "New connection! ({$conn-&gt;remoteAddress})\n";    
}
</code></pre>

<blockquote>
  <p>Call to undefined method MyApp\Chat::send()</p>
</blockquote>

<p>2) What to do so that when a message is sent all the parties can view it including the one who is sending it (that's the way how every chat works)?</p>

<p><strong>JS</strong></p>

<pre><code>var conn = new WebSocket('ws://localhost:8080');

conn.onopen = function(e) {
    //console.log("Connection established!");
    $("#chat_window #messages_list").append("&lt;li class='join_disconnect'&gt;127.0.0.1 Online&lt;/li&gt;");
}
conn.onmessage = function(e) {
    //console.log(e.data);
    $("#chat_window #messages_list").append("&lt;li class='thread'&gt;"+e.data+"&lt;/li&gt;");
}
conn.onclose = function(e) {
    //console.log("Connection Disconnected!");
    $("#chat_window #messages_list").append("&lt;li class='join_disconnect'&gt;127.0.0.1 Offline&lt;/li&gt;");
};



$(document).ready(function(){

        disable_button();


        //EMERGENCY EXIT
        $('#exit').click(function(){
                window.location.replace('http://www.google.com');
        });


        //PREVENT BLANK INPUT
        $('#msg').on('keyup', function(e){

                if($(this).val().length&gt;0){
                    enable_button();
                }
                else{
                    disable_button();
                }

        });

        //SEND MESSAGE
        $('#snd').click(function(){
            var thread = $('#msg').val();
            //console.log(thread);
            //conn.send(thread);
            $.ajax({
                type:'POST',
                url: './bin/send-message.php',
                data: {msg: thread},
                success: function(response){
                    //alert(response);
                    if(response!=1){
                        $('#msg').val('');
                        disable_button();
                    }
                }
            });
        });

        //ENABLE BUTTON
        function enable_button() {
            var element = document.getElementById('snd');
            $(element).addClass('active');
            element.style.pointerEvents = '';
        }

        //DISABLE BUTTON
        function disable_button() {
            var element = document.getElementById('snd');
            $(element).removeClass('active');
            element.style.pointerEvents = 'none';
        }


});
</code></pre>

<p>I know these are a lot of questions but I really want to know how. If there are any step by step easy to learn tutorials those are also welcome.</p>