6

Exercise : write a log service

Server

Write a server program called slog which listens to an INET TCP socket.
Once the connection with a client is established, read the messages it sends and log them in a file.
A client must be able to send several messages.
The server stays alive after the connection is closed.
The log is preserved between executions of the server (create the log file if necessary).

The program expects only one message:

LOG text'\n'

Note that a message must explicitly start by the word LOG followed by a space and end with a newline.
The total maximum length of a message (prefix + space + text + newline) is set to 1024 bytes.

Every logged message is timestamped and prefixed by the word LOG and the IP address of the sender:

24/12/10 23:59:05 127.0.0.1 LOG Santa is coming!

If a message is too long, truncate it.
If a message is ill formed, close the connection and write the error in the log (intrusion detection):

31/12/10 12:02:14 127.0.0.1 BADMSG

When the program is started and stopped, log the event:

31/12/10 08:12:45 127.0.0.1 START

31/12/10 18:27:19 127.0.0.1 STOP

Client

Write a client program called clog which opens a connection with the server and sends it every single line of text read from the standard input.

Options

Add reading parameters for the server and the client from the command-line.

slog [-p port_num] [log_file]

clog [-h host_name] [-p port_num]

Write a server capable of managing several connections at the same time.
Test it with at least 2 clients and show in the log that messages are actually intermixed.

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].