Sockets.io connecting, but not sending messages
<p>I have a Java Server that listens for messages on a Ionic 2 Client.  I can get the client and server to connect via Sockets.io, and I can get the server to send the client a message successfully. However, I cannot get the client to send the server a message.</p>

<p>i.e. the javascript <code>send(message)</code> is invoked, which should <code>emit</code> the message to the server, but it is not (<code>"onSend"</code> is never printed).  But the <code>"Welcome to the chat!"</code> message is being sent from server to client successfully.</p>

<p>Any suggestions welcome please?</p>

<p><strong>Java (Server)</strong></p>

<pre><code>import com.corundumstudio.socketio.AckRequest;
import com.corundumstudio.socketio.Configuration;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.SocketIOServer;
import com.corundumstudio.socketio.listener.ConnectListener;
import com.corundumstudio.socketio.listener.DataListener;
import com.corundumstudio.socketio.listener.DisconnectListener;

public class Server {

    public static void main(String[] args) {
        Configuration config = new Configuration();
        config.setHostname("localhost");
        config.setPort(3700);
        final SocketIOServer server = new SocketIOServer(config);

        server.addConnectListener(new ConnectListener() {
            @Override
            public void onConnect(SocketIOClient client) {
                System.out.println("onConnected");
                client.sendEvent("chat_message:message", new Message("", "Welcome to the chat!"));
            }
        });

        server.addDisconnectListener(new DisconnectListener() {
            @Override
            public void onDisconnect(SocketIOClient client) {
                System.out.println("onDisconnected");
            }
        });

        server.addEventListener("chat_message:send", Message.class, new DataListener&lt;Message&gt;() {
            @Override
            public void onData(SocketIOClient client, Message data, AckRequest ackSender) throws Exception {
                System.out.println("onSend: " + data.toString());
                server.getBroadcastOperations().sendEvent("chat_message:message", data);
            }
        });

        System.out.println("Starting server...");
        server.start();
        System.out.println("Server started");

    }
}
</code></pre>

<p><strong>Ionic 2 TypeScript (Client)</strong></p>

<pre><code>import { Component, NgZone } from '@angular/core';
import { Http } from "@angular/http";
declare var io;
//require ('io');

@Component({
  templateUrl: 'build/pages/chat/chat.html',
})

export class ChatPage {

  private socketHost: string = "http://localhost:3700";
  private messages: string[] = [];
  private zone: NgZone = null;
  private chatBox: string = null;
  private socket: any = null;

  constructor(http: Http) {
    this.messages = [];
    this.zone = new NgZone({ enableLongStackTrace: false });
    let url = this.socketHost + "/fetch";
    //let url = this.socketHost;
    http.get(url).subscribe((success) =&gt; {
      var data = success.json();
      for (var i = 0; i &lt; data.length; i++) {
    console.log('sub: '+data[i].message);
        this.messages.push(data[i].message);
      }
    }, (error) =&gt; {
      console.log(JSON.stringify(error));
    });
    this.chatBox = "";


    this.socket = io(this.socketHost);
    this.socket.on("chat_message:message", (msg) =&gt; {
      this.zone.run(() =&gt; {
    console.log('run: '+msg);
    console.log(msg);
        this.messages.push(msg);
      });
    });
  }

  send(message) {
    if (message &amp;&amp; message != "") {
    console.log('send: '+message);
      this.socket.emit("chat_message:send", message);
    }
    this.chatBox = "";
  }
}
</code></pre>