title: ORIGINAL EXCEPTION: ReferenceError: io is not defined
body: <p>I am trying to create a chat app using Ionic2 (Angular2). I have a <strong>Java Server</strong> and <strong>Ionic 2 Client</strong>.</p>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>ORIGINAL EXCEPTION: ReferenceError: io is not defined</p>
  </blockquote>
  
  <p>Any suggestions please?</p>
  
  <h1>Client</h1>
  
  <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++) {
          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", (msg) =&gt; {
        this.zone.run(() =&gt; {
          this.messages.push(msg);
        });
      });
    }
  
    send(message) {
      if (message &amp;&amp; message != "") {
        this.socket.emit("chat_message", message);
      }
      this.chatBox = "";
    }
  }
  </code></pre>
  
  <h1>HTML</h1>
  
  <pre><code>&lt;ion-navbar *navbar&gt;
      &lt;ion-title&gt;
          Chat
      &lt;/ion-title&gt;
  &lt;/ion-navbar&gt;
  
  &lt;ion-content class="home"&gt;
      &lt;ion-list&gt;
          &lt;ion-item *ngFor="let message of messages"&gt;{{message}}&lt;/ion-item&gt;
      &lt;/ion-list&gt;
  &lt;/ion-content&gt;
  
  &lt;ion-footer-bar&gt;
      &lt;ion-input&gt;
          &lt;input type="text" [(ngModel)]="chatBox" placeholder="Message..." /&gt;
          &lt;button (click)="send(chatBox)"&gt;Send&lt;/button&gt;
      &lt;/ion-input&gt;
  &lt;/ion-footer-bar&gt;
  </code></pre>
  
  <p><strong>index.html</strong></p>
  
  <pre><code>&lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <h1>Server</h1>
  
  <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("message", new Message("", "Welcome to the chat!"));
              }
          });
          server.addDisconnectListener(new DisconnectListener() {
              @Override
              public void onDisconnect(SocketIOClient client) {
                  System.out.println("onDisconnected");
              }
          });
          server.addEventListener("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("message", data);
              }
          });
          System.out.println("Starting server...");
          server.start();
          System.out.println("Server started");
  
      }
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I add the following to <code>index.html</code>, and I don't get any errors any more:</p>
  
  <p><code>&lt;script src="https://cdn.socket.io/socket.io-1.4.5.js"&gt;&lt;/script&gt;</code></p>
  
  <p>But it just hangs. And in Firebug, I can see that the following request is just hanging:</p>
  
  <blockquote>
    <p><code>GET http://localhost:3700/</code></p>
  </blockquote>
  
  <p>The following is printed in the server console:</p>
  
  <blockquote>
    <p>onConnected</p>
  </blockquote>
  
  <p>When the server is not running the following request times out as expected, but when the server is running, the request does return, but with a <code>null</code> response:</p>
  
  <pre><code>GET http://localhost:3700/socket.io/?EIO=3&amp;transport=...LRQn9sx&amp;sid=53081e79-81f3-4fc0-8fb7-17c8673938ca        
  200 OK
          27ms
  </code></pre>
  
  <p>So it suggests that my server code or the communication between client and server is wrong I think.</p>
  
  <p>Any ideas?</p>