In this recipe, we continue to explore the groovy
command's features at one's disposal. This time, we show how to create a process capable of serving client requests through TCP/IP directly from the command line and with one line of code.
The command-line option that we are going to use for this purpose is -l
:
-l
option, it is trivial to start a simple socket server in Groovy:groovy -l 4444 -e "println new Date()"
groovy is listening on port 4444
What time is it?
), and press Enter. The server should reply with a date/time string back as shown in the following screenshot:In this way, you can quite easily organize communication channels for ad hoc notifications on different hosts.