help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] bi-directional socket client / server example code?


From: John Kearney
Subject: Re: [Help-bash] bi-directional socket client / server example code?
Date: Thu, 20 Jun 2013 15:02:36 +0200

Actually I've found the easiest way to deal with \n vs \r problem is
IFS=$' \t\n\r'
Solves the problem for me.


On Thu, Jun 20, 2013 at 2:28 PM, Greg Wooledge <address@hidden> wrote:
On Thu, Jun 20, 2013 at 12:13:41PM +0000, adrelanos wrote:
> Do you know some example code using tcpserver or something similar
> (multiple clients)?

imadev:~$ tcpserver 0 2345 /bin/bash -c $'while read -r; do echo "${REPLY%$\'\\r\'} to you too"; done'

address@hidden:~$ nc -q1 imadev 2345 <<< 'hello'
hello to you too

arc3:~$ telnet imadev 2345
Trying 10.76.173.78...
Connected to imadev.eeg.ccf.org.
Escape character is '^]'.
good-bye
good-bye to you too
wot
wot to you too
^]q

telnet> q
Connection closed.


In practice, for any non-trivial example, I would write a script and
use tcpserver 0 $port /my/script.  The 0 means 0.0.0.0 or "bind to all
interfaces".  If you only want the service to listen on localhost, which
is quite reasonable in many cases, then use localhost instead of 0.

It's important to strip carriage returns from each line of input.  They
will be present some of the time, but not all of the time, depending
on the options selected by the client.  E.g. nc strips them, but telnet
sends them.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]