Socket API examples question

i’m a novice linux and hologram api user.

for the Socket API (Embedded APIs), does anyone have suggestions for how to encapsulate the commands used in the examples into a shell script? in other words, if im not able to manually enter them, and want a script to periodically execcute, how to?

specifically, the example shown:

$ nc cloudsocket.hologram.io 9999

{“s”:“ABCD”,“c”:“WXYZ”,“d”:“Hello, World!”,“t”:“TOPIC1”}

thx!

I see you are already using NetCat manually which can be put into a shell script so I assume your question is about scheduling the shell script to execute, correct? If so I would recommend setting up a CRON job. You can read more about CRON here: Newbie: Intro to cron

If you have more questions about general Linux, Shell, NC, etc. then Stack Overflow would be a better place to ask Newest 'shell' Questions - Stack Overflow

Cheers and thanks for using Hologram!

To add to Ben’s explanation: netcat is designed to operate as an interactive session, but you can use the Unix ‘echo’ command to pipe input to nc:

echo '{"s":"ABCD","c":"WXYZ","d":"Hello, World!","t":"TOPIC1"}' | nc cloudsocket.hologram.io 9999

Some older versions of netcat (like the one that ships in OS X) will hang up before getting a reply, which causes Hologram to ignore the message. You can work around this by telling netcat to delay for 1 second before hanging up:

echo '{"s":"ABCD","c":"WXYZ","d":"Hello, World!","t":"TOPIC1"}' | nc -i1 cloudsocket.hologram.io 9999
1 Like