[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] bi-directional socket client / server example code?
From: |
Greg Wooledge |
Subject: |
Re: [Help-bash] bi-directional socket client / server example code? |
Date: |
Mon, 17 Jun 2013 12:59:24 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Mon, Jun 17, 2013 at 04:33:00PM +0000, adrelanos wrote:
> is it possible to do with bi-directional socket client / server
> communication with bash? Is there some example code?
Client only.
exec 3<> /dev/tcp/"$host"/"$port" || exit
IFS= read -r banner <&3
banner=${banner%$'\r'}; echo "Banner: <$banner>"
message='HELO world'
printf '%s\r\n' >&3
IFS= read -r response <&3
response=${response%$'\r'}; echo "Response: <$response>"
... etc. ...
exec 3>&-
If you need server sockets, you'll need to use 3rd party programs, like
tcpserver (from ucspi-tcp), or xinetd/inetd/etc.