1

node.jsサーバーがarduinoと真のTCPソケットと通信するプロジェクトがあります。彼のすべてのデータを Web ページ true a socket.io から受信し、それを TCP ソケットに転送します。すべてが正常に機能しています。次の場合を除きます。

新しいソフトウェアで arduino をダウンロードします。または、イーサネット ケーブルを抜いたとき、arduino でシリアル モニタを 2 回開いたとき。events.js:85 throw er; を取得しました。// Unhandled 'error' event Error: read ECONNRESET at exports._errnoException (util.js:746:11) at TCP.onread (net.js:550:26)

何が問題なのか知っていますか。特に自動接続機能を修正するにはどうすればよいですか。

var express = require('express');
var app     = express();
var hbs     = require('hbs');
var port    = 3000;
var http = require('http').Server(app);
var io = require('socket.io')(http);
net = require('net');
var tcpGuests = [];

app.set('view engine', 'html');
app.engine('html', hbs.__express);
app.use(express.bodyParser());
app.use(express.static('public'));


app.get('/', function(req, res) {
    res.render('index', {title:"HTML5-SuperTemplate"});
});

app.get('/about', function(req, res) {
    res.render('about', {title:"About Me"});
});

app.get('/instructions', function(req, res) {
    res.render('instructions', {title:"Instructions"});
});

app.get('/buttons', function(req, res) {
    res.render('buttons', {title:"Buttons"});
});

app.get('/Lists', function(req, res) {
    res.render('Lists', {title:"Lists"});
});

app.get('/menus', function(req, res) {
    res.render('menus', {title:"Menus"});
});

app.get('/tables', function(req, res) {
    res.render('tables', {title:"Tables"});
});

app.get('/tooltips', function(req, res) {
    res.render('tooltips', {title:"Tooltips"});
});

app.get('/typography', function(req, res) {
    res.render('typography', {title:"Typography"});
});

app.get('/hr', function(req, res) {
    res.render('hr', {title:"Horizontal Rules"});
});

app.get('/icons', function(req, res) {
    res.render('icons', {title:"ICONS"});
});

app.get('/code', function(req, res) {
    res.render('code', {title:"CODE & PRE"});
});

app.get('/tabs', function(req, res) {
    res.render('tabs', {title:"TABS"});
});

app.get('/breadcrumbs', function(req, res) {
    res.render('breadcrumbs', {title:"Breadcrumbs"});
});

app.get('/grids', function(req, res) {
    res.render('grids', {title:"Grid System"});
});

app.get('/images', function(req, res) {
    res.render('images', {title:"IMAGES"});
});

app.get('/slideshow', function(req, res) {
    res.render('slideshow', {title:"Slideshow"});
});

app.get('/forms', function(req, res) {
    res.render('forms', {title:"Forms"});
});

app.get('/classes', function(req, res) {
    res.render('classes', {title:"Classes"});
});

io.on('connection', function(socket){
  socket.on('chat message', function(msg){
    io.emit('chat message', msg);
    console.log('received on io-socket:'+msg);
  });
});

http.listen(3000, function(){
  console.log('listening on *:3000');
});

// socket.io, I choose you
io.on('connection', function(socket){
  socket.on('chat message', function(msg){
    io.emit('chat message', msg);
    console.log('received on io-socket:'+msg);
    for (g in tcpGuests) {
        tcpGuests[g].write(msg);
    }
  });
});

//tcp socket server
var tcpServer = net.createServer(function (socket) {
  console.log('tcp server running on port 1337');
  console.log('web server running on http://localhost:3000');
});

tcpServer.on('connection',function(socket){
    socket.write('connected to the tcp server\r\n');
    console.log('num of connections on port 1337: ' + tcpServer.connections);

    tcpGuests.push(socket);


    socket.on('data',function(data){
        console.log('received on tcp socket:'+data);
        socket.write(' msg received\r\n');


        //send data to guest socket.io chat server
        for (g in io.clients) {
            var client = io.clients[g];
            client.send({message:["arduino",data.toString('ascii',0,data.length)]});
          }
    })
});
tcpServer.listen(1337);
4

1 に答える 1