Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • Network programming in a shell is next to impossible, due to the difficulty of handling asynchronous events, and the binary nature of packets. Use a language that supports asynchronous binary network traffic (C, Perl, Rust, etc). Commented Nov 13 at 0:52
  • And for something like this, use an expect library for, e.g., perl or python. or even the original tcl expect. This is exactly the kind of thing that expect and friends are for: open a connection to something, wait for a short time or for a known prompt, send whatever, wait for a response & do something with it. They're often used to wait for and respond to login and password prompts, but aren' limited to that. One other alternative if your tcp server on port 1234 uses some well-known protocol, there's a small chance that perl has a library that speaks it. And python might too. Commented Nov 13 at 2:01
  • 1
    @cas: commandline expect -- at least -- connects to a process/program that does I/O over a TTY (by giving it a PTY instead); a socket isn't a TTY and isn't even a first-class file although some shells, and gawk, make it partly work like one Commented Nov 13 at 7:17
  • What do you mean by "response"? Something sent over the TCP connection by the application receiving the file at the other end? The TCP FIN received from the other end? The TCP ACK received for the last data packet that was sent? Commented Nov 13 at 7:25
  • If you don't half-close the connection after having sent the file, how is the other end to know when the file has been transferred fully? Does it know in advance the size of the file it is to receive? Commented Nov 13 at 7:26