mardi 10 mai 2016

Building scalable tcp server in node js

So I'm not sure my title is the most accurate but I tried to give the best explenation I could.

I was recently at a job interview where I was asked this question(More or less as I don't remember the full question. This is the out of the top of my head):

You need to make a simple tcp server that can be accessed through puTTy (or any other client for that matter).

Once you are in, you need to write:

login < username > (Doesn't matter what username).

once you are logged in you have 3 operations you can do:

  • showDevices - will return a list of devices (Currently we have lamp and an airconditioner) - we can write mock objects. Let's assume they have a number Id.

  • Switch < deviceId > < on|off > - sets the device on or off.

  • SetValue < deviceId > < double > - set's the device's ranged value (Air condition tempature)

Important things:

  • Separation - Separate the logic and communication layer. We work with a telenat server now but we will want to switch to an http server in the future. The process should be easy.

  • Extensibility- We currently have 4 operations (login, showDevices, Switch, SetValue) - write the server so it would be very easy for other programmers to add another operation. The code should be self-explanatory

The assignment could have been written in any language. I tried writing it in C# until I was stuck and couldn't continue. Lately I'm more into Node js and decided to give this another go... so I'm asking you guys for some helpful directons to this solution.

  • How do I best seperate between the communication and the logic layer?

  • Is there some sort of design pattern I should implement for adding commands easier? (I looked at the command design pattern and I couldn't figuere out if it was meant for this kind of situation)

  • Anything that can actually directs me in the right track (without telling me exactly what to do) will be appreciated.

Thanks!

Aucun commentaire:

Enregistrer un commentaire