For the port listening feature to work, you must also use the -nor options -p.
Example:
println "Got $line from socket"
$ groovy -n -l8888 test.groovy &
groovy is listening on port 8888
$ echo hello | nc localhost 8888
Got hello from socket
$
EDIT: Also note that you are getting one line from a socket, not a full HTTP request. Therefore, in the case of GET, you will get several lines for each request, looking something like this:
GET / HTTP/1.1
Host: localhost:8888
[a variable number of headers]
. POST :
POST / HTTP/1.1
Host: localhost:8888
[a variable number of headers]
d=test
, , GET, POST. , POST , groovy , , .
, . - :
System.err.println(line)
if (line.size() == 0) {
println "HTTP/1.1 200 OK\r\n\r\nhello"
socket.shutdownOutput()
}
groovy , POST.