Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fix "Unexpected token ILLEGAL" error. #3

Merged
merged 1 commit into from

2 participants

@sudodo

I've fixed issue no.2.
#2

Thank you for great code.

@andregoncalves andregoncalves merged commit ed2353f into andregoncalves:master
@andregoncalves

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 28, 2011
  1. fix "Unexpected token ILLEGAL" error.

    Akihito Sudo authored
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 5 deletions.
  1. +18 −5 server.js
View
23 server.js
@@ -25,16 +25,29 @@ var clients = [];
var twitter = http.createClient(80, "stream.twitter.com");
var request = twitter.request("GET", "/1/statuses/filter.json?track=" + KEYWORD, headers);
+
+var message = "";
+
request.addListener('response', function (response) {
response.setEncoding("utf8");
response.addListener("data", function (chunk) {
- // Send response to all connected clients
-
- clients.each(function(c) {
- c.write(chunk);
+
+ message += chunk;
+
+ var newlineIndex = message.indexOf('\r');
+ // response should not be sent until message includes '\r'.
+ // Look at the section titled "Parsing Responses" in Twitter's documentation.
+ if (newlineIndex !== -1) {
+ var tweet = message.slice(0, newlineIndex);
+ clients.forEach(function(client) {
+ // Send response to all connected clients
+ client.write(tweet);
+ });
+ }
+ message = message.slice(newlineIndex + 1);
});
- });
+
});
request.end();
Something went wrong with that request. Please try again.