Home > Archive > Unix Programming > August 2006 > Text Output to Shell
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Text Output to Shell
|
|
| vivekian 2006-08-22, 7:01 pm |
| Hi,
I am working as an teaching assistant for a computer networking class
and have been assigned to write the server side of a small networking
application meant as an assignment for the students. The application is
meant to fulfill the following objectives :
1. Function as the server side of the application.
2. When the students are developing the client side , it should guide
them as a diagnostic tool. e.g. if they send a message and the format
is not correct , it should let them know this and indicate the correct
format.
It is a console based application where output is text. There are
multiple threads running within the application. Are there any
suggestions as to how the output messages / diagnostics messages be
displayed inorder that the different threads throwing out information
can be seperated ? The idea is to give the students the relevant
information without confusing them too much. Any suggestions would be
helpful.
thanks in advance,
vivekian
| |
| Logan Shaw 2006-08-22, 7:01 pm |
| vivekian wrote:
> I am working as an teaching assistant for a computer networking class
> and have been assigned to write the server side of a small networking
> application meant as an assignment for the students. The application is
> meant to fulfill the following objectives :
>
> 1. Function as the server side of the application.
> 2. When the students are developing the client side , it should guide
> them as a diagnostic tool. e.g. if they send a message and the format
> is not correct , it should let them know this and indicate the correct
> format.
>
> It is a console based application where output is text.
OK, but this has nothing to do with sending output to the shell.
The shell is program. Maybe you want to send output to the
terminal, which is different from the shell and which is something
the shell sends output to as well.
> There are
> multiple threads running within the application. Are there any
> suggestions as to how the output messages / diagnostics messages be
> displayed inorder that the different threads throwing out information
> can be seperated ? The idea is to give the students the relevant
> information without confusing them too much.
If you are using the stdio.h routines, or one of lots of other APIs,
you'll have to serialize access to library calls anyway. So, serialize
output, and print one line messages from each thread. At the beginning
of the line, but an indentifier (textual and symbolic, numeric,
indentation level, whatever) that shows what thread the message has
come from.
Since writing to the terminal (or to stdout) will sometimes block, if
you cannot tolerate blocking, you might be able to write messages into a
buffer (serializing access to the buffer, of course), then have another
thread whose job it is to consume data from the buffer and write it to
the terminal, or to stdout. Of course, your buffer may eventually
fill and cause blocking anyway, but maybe you can use an arbitrary
buffer or maybe you have a finite amount of data to write there.
Alternatively, you could use curses or similar and divide the screen
up into separate regions, then have each thread write to a separate
region.
- Logan
| |
| Josef Moellers 2006-08-23, 4:00 am |
| vivekian wrote:
> Hi,
>=20
> I am working as an teaching assistant for a computer networking class
> and have been assigned to write the server side of a small networking
> application meant as an assignment for the students. The application is=
> meant to fulfill the following objectives :
>=20
> 1. Function as the server side of the application.
> 2. When the students are developing the client side , it should guide
> them as a diagnostic tool. e.g. if they send a message and the format
> is not correct , it should let them know this and indicate the correct
> format.
>=20
> It is a console based application where output is text. There are
> multiple threads running within the application. Are there any
> suggestions as to how the output messages / diagnostics messages be
> displayed inorder that the different threads throwing out information
> can be seperated ? The idea is to give the students the relevant
> information without confusing them too much. Any suggestions would be
> helpful.=20
I'd read your problem as
"If the client side sends a badly formatted request to the server, the=20
server should alert the user of this error."
That would be quite difficult to achieve, since that would require=20
assistance of the client which is obviously not functioning correctly.
While one could think of several possible solutions storing the error=20
message and requiring the student to pick it up, this would be a tricky=20
thing to achieve, most likely causing privacy problems (i.e. you must=20
prevent others to see one's errors).
Much of a robust and reasonably secure implementation relies on the=20
ability of the server to identify the student correctly (not in "this is =
John Smith", but rather in "I'm sending this error message to the right=20
person"). Is each client running on a separate system, i.e. can you=20
identify a client by the IP-address of his/her host?
I'd think of setting up a seperate communication channel to send error=20
messages. In order to test their client, the students must first open=20
e.g. a telnet session to the server host (note that the telnet program=20
allows you to specify an arbitrary port!).
The server program will then create one (or more) new socket(s) with (a) =
new port number(s) and tell the student which port(s) to use. Then the=20
student has to connect to the given port(s). The main problem here is=20
that this is error-prone as the students will have to copy the=20
port-number(s) and handle this appropriately in their client (i.e. pick=20
it/them up from e.g. the command line). You'd use select() to see from=20
which port data arrives and you'd distribute the data accordingly. As=20
all is handled in one thread, you can simply send the error message to=20
the telnet port (take care of flushing!)
HTH,
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
| |
|
| On 2006-08-23, vivekian <viveklinux@gmail.com> wrote:
> Hi,
> It is a console based application where output is text. There are
> multiple threads running within the application. Are there any
> suggestions as to how the output messages / diagnostics messages be
> displayed inorder that the different threads throwing out information
> can be seperated ?
can you put the response back out the same socket that the request came in
through or put it in a log file that's identifiable by ip address etc?
--
Bye.
Jasen
|
|
|
|
|