Professional Documents
Culture Documents
EJERCICIO 1
ENUNCIADO: Se quiere implementar un servidor net que reciba peticiones de cmputo de las
funciones matemticas factorial y fibonacci.
Se pide completar la implementacin del servidor net, teniendo en cuenta las siguientes
especificaciones:
- Cada cliente net que se conecte al servidor enviar una peticin de cmputo de la
funcin fact (factorial) o la funcin fibo (fibonacci). Dicha peticin ser un objeto
serializado con JSON. El objeto contendr dos propiedades: una propiedad llamada
func, cuyo valor ser fact o fibo segn la funcin que se desee calcular; y otra
propiedad llamada numb, cuyo valor ser el argumento de entrada para la funcin a
calcular.
EJERCICIO 2
ENUNCIADO: Se quiere implementar un cliente net que enve peticiones de cmputo de las
funciones matemticas factorial y fibonacci al servidor del anterior ejercicio.
Se pide completar la implementacin del cliente net, teniendo en cuenta las siguientes
especificaciones:
- El cliente deber construir un objeto con dos propiedades, func y numb, cuyos valores
sern los recibidos como argumentos en la invocacin del programa. Dicho objeto,
serializado con JSON, ser el contenido del nico mensaje que el cliente enviar al
servidor.
net.createServer([options][, connectionListener])
Creates a new server. The connectionListener argument is automatically set as a listener for the
'connection' event.
net.Socket
This object is an abstraction of a TCP or local socket. net.Socket instances implement a duplex
Stream interface. They can be created by the user and used as a client (with connect()) or they
can be created by Node.js and passed to the user through the 'connection' event of a server.
Event: 'data'
Emitted when data is received. The argument data will be a Buffer or String. Encoding of data is
set by socket.setEncoding(). Note that the data will be lost if there is no listener when a Socket
emits a 'data' event.
Event: 'end'
Emitted when the other end of the socket sends a FIN packet.
Event: 'error'
Emitted when an error occurs. The 'close' event will be called directly following this event.