Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6590845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:21:03+00:00 2026-05-25T17:21:03+00:00

i’m writing application like social network where in my application can show status update

  • 0

i’m writing application like social network where in my application can show status update and chat . when i search on internet i found node.js for long polling technology and i think i can use that for chat and streaming page in my application. but when i use node.js i have a stack

this is a technology i want to my project:
1) i’m using codeigniter for framework and mysql database in address localhost:81/myproject
2) and using node.js in port 127.0.0.1:8080 to chat and streaming page

this is code javascript server with node.js name is server.js

var sys = require("sys"),
http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs"),
events = require("events");

function load_static_file(uri, response) {
var filename = path.join(process.cwd(), uri);
path.exists(filename, function(exists) {
    if(!exists) {
        response.writeHead(404, {"Content-Type": "text/plain"});
        response.write("404 Not Found\n");
        response.end();
        return;
    }

    fs.readFile(filename, "binary", function(err, file) {
        if(err) {
            response.writeHead(500, {"Content-Type": "text/plain"});
            response.write(err + "\n");
            response.end();
            return;
        }

        response.writeHead(200);
        response.write(file, "binary");
        response.end();
    });
});
   } 
   var local_client = http.createClient(81, "localhost");

   var local_emitter = new events.EventEmitter();

   function get_users() {
      var request = local_client.request("GET", "/myproject/getUser", {"host": "localhost"});

request.addListener("response", function(response) {
    var body = "";
    response.addListener("data", function(data) {
        body += data;
    });

    response.addListener("end", function() {
        var users = JSON.parse(body);
        if(users.length > 0) {
            local_emitter.emit("users", users);
        }
    });
});

request.end();
 }

 setInterval(get_users, 5000);

 http.createServer(function(request, response) {
    var uri = url.parse(request.url).pathname;
    if(uri === "/stream") {

    var listener = local_emitter.addListener("users", function(users) {
        response.writeHead(200, { "Content-Type" : "text/plain" });
        response.write(JSON.stringify(users));
        response.end();

        clearTimeout(timeout);
    });

       var timeout = setTimeout(function() {
        response.writeHead(200, { "Content-Type" : "text/plain" });
        response.write(JSON.stringify([]));
        response.end();

        local_emitter.removeListener(listener);
       }, 10000);

   }
   else {
       load_static_file(uri, response);
   }
  }).listen(8383);

  sys.puts("Server running at http://localhost:8383/");

now in codeigniter side i making webservices on url http://localhost:81/myproject/getUser with response is json format and i access this with session auhtentication if not is redirect to login page.

[{"user_id":"2a20f5b923ffaea7927303449b8e76daee7b9b771316488679","token":"3m5biVJMjkCNDk79pGSo","username":"rakhacs","password":"*******","name_first":"rakha","name_middle":"","name_last":"cs","email_id":"email@gmail.com","picture":"img\/default.png","active":"1","online":"0","created_at":"2011-09-20 11:14:43","access":"2","identifier":"ae70c3b56df19a303a7693cdc265f743af5b0a6e"},{"user_id":"9a6e55977e906873830018d95c31d2bf664c2f211316493932","token":"RoUvvPyVt7bGaFhiMVmj","username":"ferdian","password":"*****","name_first":"willy","name_middle":"","name_last":";f;w","email_id":"email1@gmail.com","picture":"img\/default.png","active":"1","online":"0","created_at":"2011-09-20 11:47:20","access":"2","identifier":"1ccd4193fa6b56b96b3889e59c5205cc531177c9"}]

this is the point problem when i execute node server.js
i get error like this undefined:0
sysntaxerror:unexpected end of input
at object.parse(native)

i don’t know about that error i think because i using session ? but i’m not sure.
when i test using test.js for testing my webservices

var http = require("http")
var options = {
    host: 'localhost',
    port: 81,
    path: '/myproject/getUser',
    method: 'GET'
};

var req = http.request(options, function(res) {
    console.log('STATUS: ' + res.statusCode);
    console.log('HEADERS: ' + JSON.stringify(res.headers));
    res.setEncoding('utf8');
    res.on('data', function (chunk) {
    console.log('BODY: ' + chunk);
   });
});
req.on('error', function(e) {
   console.log('problem with request: ' + e.message);
});
// write data to request body
req.write('data\n');
req.write('data\n');
req.end();

and this is the output

problem with request: parse error

but when i using another webservice who has been response json format too and not using session that’s work i can get the body response..if this problem is session how i can fix this?..this is can make me confused..thanks for your comment

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:21:03+00:00Added an answer on May 25, 2026 at 5:21 pm

    hard to say but I would primary try to send an object in jSON and not directly an array. i.e. just encapsulate the array into an object:

    {"data":[…]}
    

    This “may” be causing the parse error.

    Something else, for this purpose, it won’t be bad to add the following to your responding PHP method:

    header('Cache-Control: no-cache, must-revalidate');
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    header('Content-type: application/json');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
Does anyone know how can I replace this 2 symbol below from the string
I am writing an app with both english and french support. The app requests
I'm parsing an XML file, the creators of it stuck in a bunch social

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.