I'm trying to develop an android application which will connect to the node.js server. Here's error msg:
04-28 14:24:52.250: W/System.err(811): io.socket.SocketIOException: Error while handshaking
04-28 14:24:52.250: W/System.err(811): at io.socket.IOConnection.handshake(IOConnection.java:322)
04-28 14:24:52.259: W/System.err(811): at io.socket.IOConnection.access$600(IOConnection.java:39)
04-28 14:24:52.259: W/System.err(811): at io.socket.IOConnection$ConnectThread.run(IOConnection.java:199)
04-28 14:24:52.259: W/System.err(811): Caused by: java.lang.ArrayIndexOutOfBoundsException
04-28 14:24:52.306: W/System.err(811): at io.socket.IOConnection.handshake(IOConnection.java:318)
04-28 14:24:52.306: W/System.err(811): ... 2 more
Server:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8881, '192.168.1.107');
console.log('Server running at http://192.168.1.107:8881/');
Client:
public class RestClientActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
SocketIO socket = new SocketIO("http://192.168.1.107:8881/");
socket.connect(new IOCallback() {
@Override
public void onMessage(JSONObject json, IOAcknowledge ack) {
try {
System.out.println("Server said:" + json.toString(2));
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onMessage(String data, IOAcknowledge ack) {
System.out.println("Server said: " + data);
}
@Override
public void onError(SocketIOException socketIOException) {
System.out.println("an Error occured");
socketIOException.printStackTrace();
}
@Override
public void onDisconnect() {
System.out.println("Connection terminated.");
}
@Override
public void onConnect() {
System.out.println("Connection established");
}
@Override
public void on(String event, IOAcknowledge ack, Object... args) {
System.out
.println("Server triggered event '" + event + "'");
}
});
// This line is cached until the connection is establisched.
socket.send("Hello Server!");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Any ideas what I'm doing wrong? If I type http://192.168.1.107:8881/
in browser it will display me "Hello World" on the page but I can't connect using socket.io-java-client library.