[cse491] your mail

Joe Amenta amentajo at msu.edu
Tue Sep 29 11:19:38 PDT 2009


On Tue, Sep 29, 2009 at 2:02 PM, C. Titus Brown <ctb at msu.edu> wrote:

> On Tue, Sep 29, 2009 at 02:01:31PM -0400, duraira1 at msu.edu wrote:
> > Hi,
> > I just realised the format of how data given in the client affects my
> program..
> > ?
> > >python client.py ?5001 "sdd\n.\nddd"
> >
> > In the above case,I got the right answer,
> >
> > Recieved from the server: sdd
> > <186 arctic:~/cde491 >
> >
> > But incase I don't give the quotes,its kinda messy..Should I handle this
> in the server? Or the client is supposed to enter the data as string?
>
> There aren't any restrictions on how clients of the TCP echo server work,
> run,
> or otherwise take in data -- make it as freeform as you want.
>
> cheers,
> --titus
> --
> C. Titus Brown, ctb at msu.edu<http://lists.idyll.org/listinfo/cse491-fall-2009>



You need the quotes because entering \n on the command-line results in the
shell parsing it as "n", then passing on that "n" to the echo client.  To
examine how python will read in command-line arguments, run this command
followed by the command-line arguments that you are uncertain about:

python -c "print __import__('sys').argv[1:]"

In the case of sdd\n.\nddd, we get 'sddn.nddd', suggesting (correctly) that
"\n" on the command line is an escape sequence that resolves to just the
leter "n".  To get the results you want without quoting, you would have to
escape the backslash on the command line:

python client.py ?5001 sdd\\n.\\nddd

This explanation, however, is irrelevant to the operation of your echo
server.  If it helps give an insight to the way that UNIX-like shells
operate, then great!  If it adds confusion, then you can safely ignore it,
and just take this piece of advice: individual command-line arguments with
non-alphanumeric characters (such as "\", "$", "*", " ", etc) should be
escaped with single quotes (' ... ') to preserve the literal interpretation
of those characters.

--Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/cse491-fall-2009/attachments/20090929/579deae2/attachment.htm>


More information about the cse491-fall-2009 mailing list