I'm searching for a way to open a TCP connection, send a HTTP post request and keep the connection open.

It would be great if I can achieve this without administrator/root rights, from a command-line interface (CLI), cross-platform and with passing parameters.

Some background info. I managed to rebuild a direct HTTP request towards an Apple TV, in order to get a supported HTTP live stream started. In the same way as AirPlay works. I tested this in two different ways, and so I have a proof-of-concept using telnet and using PHP sockets. I want to make an open-source GitHub project adding the source-code and a small GUI (compiled executable for Linux, OSx and Windows) so that users can fill in any supported streaming URL and send it directly to their AppleTV.

A cross-platform solution will consist of at least a working executable/script for Windows, OSx and Linux. Accepting some kind of target and source, for example:

./persistent_tcp.sh -t -s http://example.com/stream.m3u8
./persistent_tcp.exe -t -s http://example.com/stream.m3u8

Inside the script I would like to specify the exact HTTP request, using the -s argument as a target stream (value in the HTTP request). Ideally it would return some kind of PID and continue instead of keeping the process "visibly" open or waiting. With the PID, I'm able to close the previous PID when a new one is started. Although this isn't necessary.

A new request will overrule the previous one on AppleTV anyway, but I want that processes cleaned up also. The reason why I want a cross-platform solution is that I can integrate it into different cross-platform GUIs as well as offering cross-platform CLI scripts to do so.

I checked out different solutions but curl and wget, including their Windows ports don't really seem to be able to do so. Telnet on windows works perfectly fine as long as the terminal/connection is open (and the user has enough rights) and PHP sockets work like a charm as long as the process/connection stays open. I don't want to use, embed PHP (although it is cross-platform) because I consider it a huge dependency (read: too big for such a task).

I don't care in what programming language I can achieve this. As long as it is efficient (read: small footprint) and not requiring too many dependencies or resources. Since that won't fit such a small task. Alternatively I'm also fine with a separate solution for Windows and one for Linux/OSx).

I'm fine with bash/sh, bat/cmd/vbs, apple script, node.js and other languages or pre-compiled or standalone/portable executable that fit the job and don't require the client to install additional software. (I can probably embed PHP, Python or Java as stand-alone, but key is efficiency. Nobody will be happy if we end up with a 50mb GUI executable, while the actual HTTP request is less then 10 lines code.)

  • 3
    For those of you following the current Site Name and Scope Proposals dialog, this is one of those edge questions that I consider on-topic. It's well-written, the problem is clearly specified, and it doesn't ask for code or code troubleshooting. – Robert Harvey Jul 23 '16 at 17:03
  • Would Python be too big a dependency Robert? I mean a25 :). – candied_orange Jul 23 '16 at 19:13
  • @CandiedOrange I don't know why my name is not shown, I will login my computer later instead of phone and try to change it. I think a solution in Python (which I would like) would be fine as long as I can embed a basic python configuration in the GUI. Personally I was thinking about using NW.JS for making the cross-platform GUI. Which will mostly use Node.js. I guess I can probably add some kind of cross-platform standalone python base which I can use to run Python scripts from inside the GUI. – Bob Ortiz Jul 23 '16 at 19:45
  • @a25 is a node.js http library or module suitable? nodejs.org/api/http.html#http_http . If you're considering various languages, Java has high quality, portable networking libraries. – Jerry101 Jul 23 '16 at 22:26
  • @Jerry101 Node.js libs or modules are suitable, they can be embedded in a NW.JS project. Java is another solution but I'd like a minimal footprint. Can I somehow embed a standalone portable java executable to run the Java code always, even when the client doesn't have java installed? – Bob Ortiz Jul 23 '16 at 22:30

ncat is available for various platforms and allows (in fact, requires) you to compose your entire HTTP request body manually. To control it you can use sh: there are various implementations available for Windows (including cygwin, GnuWin32, and Ubuntu on Windows for Win10) or you can write a separate batch or PowerShell script for Windows.

  • +1 for the great suggestion "Ncat Portable static binary ncat.exe in your nmap directory in ncat\Release. You can take it outside of the build directory and use it as a standalone exe" - secwiki.org/w/Nmap/Ncat_Portable – Bob Ortiz Aug 3 '16 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.