asked    Phoenix     2018-10-22       c       74 view        1 Answer

[SOLVED] C TCP cannot detect broken connection

This question already has an answer here:

  1 Answer  

        answered    Joanne     2018-10-22      

If the peer of a TCP connection closes the connection, it will lead to a recv call on your end to return 0. That's the way to detect closed (but not broken) connections.

If you don't currently receive anything from the peer, you need to make up a protocol on top of TCP which includes receiving data.

Furthermore, sending might not detect broken connections (like missing cables etc.) directly, as there are a lot of retransmissions and timeouts. The best way is again to implement some kind of protocol overlaying TCP, one that for example contains a kind of "are you there" message which expects a reply. If a reply to the "are you there" message isn't received within some specific timeout, then consider the connection broken and disconnect.





Your Answer





 2018-10-22         Verna

how to refresh token when expired in jwt

I am implementing JWT in my project. I implemented jwt and gave it an expiration time of 1 minute. The jwt that is generated from the api side is during login and the token and expiration details are sent in the result and are stored in local storage. How can I refresh the expired token from API side and send it back again to the client so that it can be stored in local storage and sent for every call using interceptor?this is how I created jwt and gave expiration time// let us suppose this is my inputtokenObject = { User: { username: name, pwd: pwd } };//creating a jwt her...
 angularjs                     2 answers                     55 view
 2018-10-22         Sidney

Date format in Node

I just want to help with the print date like below.Thu Sep 06 2018 18:18:26 GMT+0530I used console.log(new Date())but Output of that is 2018-09-06T12:48:25.776ZSo, I don't know how to convert it. Thanks in advance. :) I used dateformat (npm install --save dateformat):const dateFormat = require('dateformat');console.log(dateFormat(new Date(), "ddd mmm dd yyyy HH:MM:ss UTC" ));Hope it helps. [XXX]You could use some third party module to do that, like moment or date-fns. Or create the string manually.For moment, see this: https://momentjs.com/docs/#/displaying/For date-f...
 node.js                     2 answers                     54 view
 2018-10-22         Ella

es6 class methods can't reach this instance

So I made a class and have no idea why I can't reach this instance inside one method.So in my router I'm calling the method like thisimport Emails from '../controllers/emails'import router from 'express'....route.post('/', Emails.setupEmail)so after calling POST method it calls setupEmail method but it crashes with the message: TypeError: Cannot read property 'availableEmailTypes' of undefinedand the code of class:class Emails {constructor() { this.availableEmailTypes = ['registration', 'forgot-password', 'two-factor']}setupEmail(req, res) { if (!req.body.type || !re...
 javascript                     1 answers                     54 view