I had a project that node There is a real TCP socket with JS server conversations. It is receiving a socket .io from all the data from a webpage and then transferring it to the TCP socket except that everything is working properly except:
I have a new software with my Ardino Downloading, or when I unplug my Ethernet cable, when I open my serial monitor twice on the Ardino. I found the events JS: 85ft er; // Unchecked 'Error' Event Error: Read ECONNRESET in Export. _errnoException (util.js: 746: 11) On TCP .onread (net.js: 550: 26)
Do know what a problem is. How can I fix this, especially an auto-connect function?
var express = require ('express'); Var app = express (); Var hbs = Requirement ('Hbs'); Var ports = 3000; Var http = Required ('http'). Server (app); Var io = Requirement ('socket.io') (HT); Pure = requirement ('net'); Var tcpGuests = []; App.set ('visual engine', 'html'); App.engine ('html', hbs .__express); App.use (express.bodyParser ()); App.use (express.static ('public')); App.get ('/', function (Rick, Ridge) {res.render ('index', {title: "HTML5-SuperTemplate"}}}; App.get ('/ about', function (Reich, Ridge) } {Res.render ('about', {title: "About me"};}; App.get ('/ instructions', function (rik, ridge) {res.render ('instructions', {title} "Instructions"})}}; App.get ('/ buttons', function (req, res) {res.render (' buttons', {title: "buttons"})}; App.get ('/ lists ', Function (reik, ris) {res.render (' lists ', {title: "list"}}}; app.get (' / menus ', function (req, res) {res.render (' menus App, {title} "menus"}}}; App.get ('/ tables', function (req, res) {res.render ('table', {title: "tables"}}}}; Get ('/ tooltips', ph App.get ('/ typography', function (req, res) {res.render ('typography', {res .render ('tooltips', {title: "tooltips"}}}; {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 (rick, ridge) {res. Render ('code', {title: "CODE & PRE"})}}; App.get ('/ tab', function (rik, ridge) {res.render ('tab', {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' (Resize), {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); con Sole.log (received on 'IO-socket:' + Msg);});}); Http.listen (3000, function () {console.log ('listen to *: 3000');}); // socket.io, I would like you to select IO.on ('Connection', Function (Socket) {socket.on ('Chat Message', Function (msg) {io.emit ('Chat Message', msg); Log (received on 'Io-Socket:' + msg); (In GC TG Graceets) {TCPG Special [G]. Written (msg);}});}); // tcp socket server var tcpServer = net.createServer (function (socket) {console.log ('TCP server is running on port 1337'); console.log (a web running 'http: // localhost: 3000' Server); }); TcpServer.on ('connection', function (socket) {socket.write ('TCP is connected to server \ r \ n'); console.log ('num:' + tcpServer.connections of connection on port 1337); TcpGuests. (Socket); socket.on ('data', function (data) {console.log ('received on TCP socket:' + data); socket. Written ('msg received \ r \ n'); Send data to guest socket.io chat server for // (live in Io.clients) {var client = io.clients [g]; client.send ({Message: ["arduino", data.toString ('ascii' , 0, Data.length)]}}}}})}); tcpServer.listen (1337);
You have errors Gender does not receive an error message when every time a connection error (unpredictable cable is unplugged) is thrown by node.js. You can catch those errors so that the application will not leave.
Some errors Add handlers tcpServer.on ('error', ...)
, socket.on ('error', ...)
, io.on (' Error ', ...)
, etc. Perhaps some other error handlers.
No comments:
Post a Comment