I'm in the process of making an ionic app for android that will communicate with a simple Node.js server over a socket. For this purpose I'm using socket.io. I'm also using Angular.js on the client side.
I've been struggling to get the connection to work for about one week. I wan't to add here that I am in no way an expert, or even used to, javascript. I have been weeding out problems and bugs but this one error has me broken.
Failed to load resource: the server responded with a status of 404 (Not Found) http://EXTERNAL_IP:3000/socket.io/?EIO=3&transport=polling&t=1431009277925-0
To me this seems like the client is trying to get the socket.io files from the server, but the file doesn't exist on the server. I have the socket.io.js file locally in the client's file structure and links it in html as so:
<script src="js/vendor/socket-io.js"></script>
I get this error in the console both when i run via the live reload server and when the app is deployed to my Galaxy S5 running android 5.0
I have tried a lot of the suggestions both from this site and from others but to no avail. Maybe there is something with my hardware setup that doesn't want to play nice?
I have been following this tutorial: http://www.htmlxprs.com/post/6/creating-a-realtime-image-sharing-app-with-ionic-and-socketio-tutorial
But that code refuses to work as well.
server.js
var server = require('http').createServer();
var io = require('socket.io')(server);
io.sockets.on('connection', function(socket){
console.log("Socket connected");
socket.on('disconnect', function(){
console.log("Socket disconnected");
});
socket.on('echo', function(msg){
console.log("Recieved msg: " + msg);
socket.emit('echo', msg);
})
});
server.listen(3000);
services.js
angular.module('MyApp.services', []).factory('socketio', function($rootScope) {
var socket = io.connect("http://EXTERNAL_IP:3000");
return {
on: function (eventName, callback) {
socket.on(eventName, function () {
var args = arguments;
$rootScope.$apply(function () {
callback.apply(socket, args);
});
});
},
emit: function (eventName, data, callback) {
socket.emit(eventName, data, function () {
var args = arguments;
$rootScope.$apply(function () {
if (callback) {
callback.apply(socket, args);
}
});
})
}
};
});
controllers.js
angular.module("MyApp.controllers", [])
.controller("SocketCtrl", ["$scope", 'socketio', function($scope, socketio){
console.log("attempting to connect");
socketio.on("connect", function(){
console.log("Connected");
});
socketio.on("echo", function(msg){
console.log("Received msg: " + msg);
});
}]);
If anyone has any pointers at all I would be really thankful.