I am developing an application for the iPhone, and the plan is to send the JSON package so often from the application to the local web server. For this, I planned to use Alamofire . My POST method is as follows:
Alamofire.request(Alamofire.Method.POST, "http://XXX.XX.X.XX:3000/update", parameters: dictPoints, encoding: .JSON) .responseJSON {(request, response, JSON, error) in println(JSON) }
The IP address is allocated, but I made sure that it matches the IPv4 IP address of my local server. The server is configured to listen on port 3000. The server configuration looks like this:
var express = require('express'); var app = express(); var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/test'); var db = mongoose.connection; db.on('error', console.error.bind(console, 'connection error:')); db.once('open', function (callback) { console.log("MongoDB connection is open."); }); // Mongoose Schema definition var Schema = mongoose.Schema; var LocationSchema = new Schema({ //some schema here }); // Mongoose Model definition var LocationsCollection = mongoose.model('locations', LocationSchema); // URL management app.get('/', function (req, res) { res.sendFile(__dirname + '/index.html'); }); app.get('/update', function (req, res) { console.log("Got something from the phone!"); }); // Start the server var server = app.listen(3000, function () { var host = server.address().address var port = server.address().port console.log('App listening at %s:%s',host, port) })
So this server is working fine. I can check it in my browser and type in the URL: http: //127.0.0.1haps000 , and it will feed me the index.html file. If I type in http: //127.0.0.1haps000/update ... then I get the message "Got something from the phone!". message. However, when I launch my application (make sure that my phone is on the same wireless network as the server) and the Alamofire method is called ... the answer I get is zero. I also donβt see "Got something from the phone!" message. Can someone tell me why this will happen ... or better yet, how to fix it?
source share