<div class="gmail_quote">On Tue, Sep 29, 2009 at 2:02 PM, C. Titus Brown <span dir="ltr"><<a href="mailto:ctb@msu.edu">ctb@msu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Tue, Sep 29, 2009 at 02:01:31PM -0400, <a href="mailto:duraira1@msu.edu">duraira1@msu.edu</a> wrote:<br>
> Hi,<br>
> I just realised the format of how data given in the client affects my program..<br>
> ?<br>
> >python client.py ?5001 "sdd\n.\nddd"<br>
><br>
> In the above case,I got the right answer,<br>
><br>
> Recieved from the server: sdd<br>
> <186 arctic:~/cde491 ><br>
><br>
> 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?<br>
<br>
There aren't any restrictions on how clients of the TCP echo server work, run,<br>
or otherwise take in data -- make it as freeform as you want.<br>
<br>
cheers,<br>
--titus<br>
<font color="#888888">--<br>
C. Titus Brown, <a href="mailto:ctb@msu.edu">ctb@msu.edu</a><a href="http://lists.idyll.org/listinfo/cse491-fall-2009" target="_blank"></a></font></blockquote><div><br> </div></div>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:<br>
<br><span style="font-family: courier new,monospace;">python -c "print __import__('sys').argv[1:]"</span><br><br>In the case of <span style="font-family: courier new,monospace;">sdd\n.\nddd</span>, we get <span style="font-family: courier new,monospace;">'sddn.nddd'</span>, suggesting (correctly) that "<span style="font-family: courier new,monospace;">\n</span>" on the command line is an escape sequence that resolves to just the leter "<span style="font-family: courier new,monospace;">n</span>". To get the results you want without quoting, you would have to escape the backslash on the command line:<br>
<br><span style="font-family: courier new,monospace;">python client.py ?5001 sdd\\n.\\nddd</span><br><br>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 <span style="font-family: courier new,monospace;">"\", "$", "*", " ",</span> etc) should be escaped with single quotes (<span style="font-family: courier new,monospace;">' ... '</span>) to preserve the literal interpretation of those characters.<br>
<br>--Joe<br>