How do you close netcat connection after receipt of data?
I think including the -c
flag for nc
should do it. Also, are you sure you want to use Bourne shell, and not Bash? I'd suggest changing your shebang to #!/bin/bash
Client doesn't close connection to server after receiving all responses
Finally found a working way (maybe not the best but at least it's perfectly doing what I want :D)
after all functions I send a "ENDRESPONSE" message, and on my client, I test if I have this message or not :
function sendMessage {
while read line; do
if [[ $line == "ENDRESPONSE" ]]; then
break
else
echo $line
fi
done < <(netcat "$ipAddress" "$port" <<< "$*")
}
Anyway thanks for your help, I'll try to implement other solutions later !
Netcat only sends answer after I CTRL-C the connection
man nc
writes:
"netcat stays running until the network side closes" so your browser will wait forever for the data to finish. Use -q
option to quit, see the man page again: "after EOF on stdin, wait the specified number of seconds and then quit".
cat index.html | nc -lnvp 2222 -q 0
nc -l 2222
does not make sense, you need to use -p
to specify the port.
Passing parameter with special characters to Socat exec script
Socats address parser interpretes a few characters specially, these are for example:
: , ! " ' \ ( [ {
You have to escape them with backslash. Please note that you also need to escape a few special characters including \ from the shell parser.
Use options -d -d -d -d to see the parameters socat receives and uses; try something like
socat -u /tmp/nonexistingdir/x\\\\x -
to see in the error message what is left of the special characters when socat performs the final system call.
Send String over netcat connection
Try this:
echo -n 'Line of text' | nc <ip> <port>
You can also use temp file syntax:
cat <(echo "Line of test") | nc <ip> <port>
Related Topics
How to Find or Calculate a Linux Process's Page Table Size and Other Kernel Accounting
Difference Between $@ and $* in Bash Script
Loading U-Boot in Memory Instead of Flashing It
Doesn't Sh Support Process Substitution <(...)
How to Find Out What Group a Given User Has
Shell: Redirect Stdout to /Dev/Null and Stderr to Stdout
How to Send List of File in a Folder to a Txt File in Linux
How to Get Coordinates of Touchscreen Rawdata Using Linux
How to Self Dlopen an Executable Binary
Sys_Execve System Call from Assembly
Difference Between Flat Memory Model and Protected Memory Model
How to Recursively Copy a Directory into Another and Replace Only the Files That Have Not Changed
Hook Functions for Linux Filesystem
Linux Kernel System Call Returns -1 Instead of {-1, -256}
Timed Out While Waiting for the MAChine to Boot When Vagrant Up
Location of .Bashrc for "Bash on Ubuntu on Windows" in Windows 10