In a Max/MSP module I have a simple Tcp client that sends data to a server. I want to use this to send a PUT request to my MIDI/OSC controller(an Eigenharp). It asks for the PUT request to make one of its lights turn on.
Now, the following works in cURL:
curl http://localhost:1024/column/1/row/5 -X PUT --data green
However,
How can I accomplish something like that using a basic TCP stream, without any extra libraries?
Here is a generic way to figure it out (which is, so to speak, a trowel instead of fish):
First,
> nc -l -p 7070
which will begin listening to the tcp port 7070. Then (from a separate shell)
> curl http://localhost:7070/column/1/row/5 -X PUT --data green
After that nc
will print something like:
PUT /column/1/row/5 HTTP/1.1
User-Agent: (Some curl info here)
Host: localhost:7070
Accept: */*
Content-Length: 5
Content-Type: application/x-www-form-urlencoded
green
Which is more or less what you need to send through the socket.
You can use the very same nc
(netcat) utility as a network Swiss-army knife as well to send the data:
> cat request.txt | nc host port
That said, HTTP RFC is your best friend.