learnyounode icon indicating copy to clipboard operation
learnyounode copied to clipboard

Time Server - Invalid data

Open silentarrowz opened this issue 9 years ago • 2 comments

I am trying out the time server exercise and am getting invalid data error. here's the full error: learnyounode verify timer.js net.js:625 throw new TypeError('invalid data'); ^

TypeError: invalid data at Socket.write (net.js:625:11) at Socket.Writable.end (_stream_writable.js:443:10) at Socket.end (net.js:408:31) at Server. (/home/ubuntu/workspace/learnyounode/timer.js:7:12) at emitOne (events.js:77:13) at Server.emit (events.js:169:7) at TCP.onconnection (net.js:1431:8)

Your submission results compared to the expected:

             ACTUAL                                 EXPECTED                

────────────────────────────────────────────────────────────────

"" != "2016-06-15 11:00"
!= ""

Now, I know my code isnt complete yet. but i still should have got just the month displayed.

Here's my full code :

var net=require('net');
var date= new Date();
var server = net.createServer(function(socket){
    var year = date.getFullYear();
    var m = date.getMonth();
    //socket.write(month);
    socket.end(m);
});
server.listen(process.argv[2]);

silentarrowz avatar Jun 15 '16 11:06 silentarrowz

Seems like you have commented out the socket.write() statement, which means no data is sent at all through the socket at the moment.

tschoffelen avatar Jul 13 '16 07:07 tschoffelen

getMonth() returns 0 on January, 1 on February, etc. socket.end(0) returns "".

righght avatar Feb 22 '17 20:02 righght