October 15, 200817 yr Suggestions sought .... what else small and scriptable, other than awk and netcat, can you use to listen to a tcp socket and send text to a browser?
October 15, 200817 yr Suggestions sought .... what else small and scriptable, other than awk and netcat, can you use to listen to a tcp socket and send text to a browser? Would you believe the shell? Here is an interesting web-page: http://blogmag.net/blog/read/49/Network_programing_with_bash Joe L. Check out this greatly simplified version of "wget" ( i don't think it works on binary files, but you can see the syntax to connect to a tcp socket.) [pre] #!/bin/bash #http://blogmag.net/blog/read/49/Network_programing_with_bash # PATH=${2-/} exec 6<>/dev/tcp/$1/80 echo -e "GET ${PATH} HTTP/1.1" >&6 echo -e "Host: $1\nConnection: close\n" >&6 echo "Reading: http://${1}${PATH}" >&2 #read and discard the header while read <&6 do LINE=${REPLY//$'\r'/} if [ -z "$LINE" ]; then break fi done #read the page while read <&6 do echo -n $REPLY >&1 done # close the file descriptor exec 6<&- exec 6>&- [/pre]
October 15, 200817 yr Author Ahh yes... the line: exec 6<>/dev/tcp/$1/80 is what I needed. Thanks! Now I just need to figure out how to either 1) disable buffering, 2) set a small buffer, or 3) flush the buffer.
October 16, 200817 yr Not sure what you are trying to do, however it is possible to have a bash shell spawned from inetd which will connect stdin and stdout to the network connection.
October 16, 200817 yr Author I know, but this is part of a utility that needs to be run and stop... I can't leave an open port hanging out like that.
October 16, 200817 yr I know, but this is part of a utility that needs to be run and stop... I can't leave an open port hanging out like that. Undertstood.
October 16, 200817 yr Author Awk and netcat were in the OP.... but both buffer output, and that won't work for this project Believe me, I tried awk for hours, but the damn buffering was killing me.
Archived
This topic is now archived and is closed to further replies.