Saturday, 4 March 2017

Problem when dealing with TCP packet

Hello, I'm trying to create a TCP server to handle packets. The packet i'm sending is being received and when printed matches what is expected. However, when I run a conditional statement against the packet things start to become weird. If I send the packet "helloworld", the server will print "helloworld" but if I try to condition the packet to see if it equals "helloworld" it returns false. To make things more obvious I have my code placed below. When the below code is run, I get the message wrong packet when it should say got expected packet. Any help would be greatly appreciated!socket.on('data', function(data) { var data = data.toString(); // Handle Packet handlePacket(data); }); function handlePacket(data) { switch(data) { case "helloworld": console.log("Got expected packet"); break; default: console.log("Wrong packet"); } }

Submitted March 04, 2017 at 10:21AM by ksmit799

No comments:

Post a Comment