Permalink
Browse files

line oriented buffer added (serial is slower than TCP)

  • Loading branch information...
1 parent e2e85c8 commit caef14cfb7fd3b159629a2ca6b85319be2ab691c @kiilo committed Dec 13, 2011
Showing with 17 additions and 6 deletions.
  1. +16 −5 server.js
  2. +1 −1 style.css
View
@@ -21,6 +21,7 @@ var fu = require("./fu"),
url = require("url"),
qs = require("querystring");
net = require("net");
+ carrier = require('carrier');
var MESSAGE_BACKLOG = 200,
SESSION_TIMEOUT = 60 * 1000;
@@ -42,7 +43,7 @@ var channel = new function () {
for (var i = 0; i < tcpGuests.length; i++) {
// ok write also to the TCP socket (arduino)
try {
- tcpGuests[i].write(text);
+ tcpGuests[i].write(text+"\n");
}
catch (eee) {
console.log("remove this socket " + i);
@@ -228,6 +229,10 @@ fu.get("/send", function (req, res) {
var tcpServer = net.createServer(function (socket) {
socket.setEncoding("utf8")
console.log('tcp server running on port' + TCPPORT);
+ var my_carrier = carrier.carry(socket);
+// my_carrier.on('line', function(line) {
+// console.log('got one line: ' + line);
+// });
});
tcpServer.on('connection',function(socket){
@@ -237,18 +242,24 @@ tcpServer.on('connection',function(socket){
var ArduinoSession = createSession("arduino"+ ArduinoNr);
channel.appendMessage("arduino"+ ArduinoNr,"join");
tcpGuests.push(socket);
+ var my_carrier = carrier.carry(socket);
- socket.on('data',function(data){
+ my_carrier.on('line', function(line) {
+ //console.log('got one line: ' + line);
+ channel.appendMessage(ArduinoSession.nick, 'msg', line);
+ });
+
+
+ //socket.on('data',function(data){
//console.log('received on tcp socket:' + data);
//socket.write('OK\n');
//send data to guest socket.io chat server
//ArduinoSession.poke();
- channel.appendMessage(ArduinoSession.nick, 'msg', data);
- });
+ //channel.appendMessage(ArduinoSession.nick, 'msg', data);
+ //});
socket.on('close',function(socket){
-
channel.appendMessage(ArduinoSession.nick, "part");
ArduinoSession.destroy(); //delete Arduino from the list
for (var i = 0; i < tcpGuests.length; i++) {
View
@@ -3,7 +3,7 @@ body {
margin: 0;
}
body, #entry {
- background: #22252a;
+ background: #223344;
color: #eee;
}
body, table {

0 comments on commit caef14c

Please sign in to comment.