groovy.ui

## Class GroovySocketServer

- java.lang.Object
- - groovy.ui.GroovySocketServer

All Implemented Interfaces:
  java.lang.Runnable

    public class GroovySocketServer
    extends java.lang.Object
    implements java.lang.Runnable

Simple server that executes supplied script against a socket.
Typically this is used from the groovy command line agent but it can be invoked programatically. To run this program from the command line please refer to the command line documentation at Groovy CLI.
Here is an example of how to use this class to open a listening socket on the server, listen for incoming data, and then echo the data back to the client in reverse order:

     new GroovySocketServer(
             new GroovyShell(),      // evaluator
             false,                  // is not a file
             "println line.reverse()",         // script to evaluate
             true,                   // return result to client
             1960)                   //port

There are several variables in the script binding:

- line - The data from the socket
- out - The output PrintWriter, should you need it for some reason.
- socket - The socket, should you need it for some reason.

### Constructor Summary

Constructors
Constructor and Description
`GroovySocketServer(GroovyShell groovy, boolean isScriptFile, java.lang.String scriptFilenameOrText, boolean autoOutput, int port)` This creates and starts the socket server on a new Thread.

### Method Summary

Methods
`void` `run()` Runs this server.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### GroovySocketServer

    public GroovySocketServer(GroovyShell groovy,
                      boolean isScriptFile,
                      java.lang.String scriptFilenameOrText,
                      boolean autoOutput,
                      int port)

This creates and starts the socket server on a new Thread. There is no need to call run or spawn a new thread yourself.

Parameters:
  `groovy` - The GroovyShell object that evaluates the incoming text. If you need additional classes in the classloader then configure that through this object.
  `isScriptFile` - Whether the incoming socket data String will be a script or a file path.
  `scriptFilenameOrText` - This will be a groovy script or a file location depending on the argument isScriptFile.
  `autoOutput` - whether output should be automatically echoed back to the client
  `port` - the port to listen on

### Method Detail

#### run

    public void run()

Runs this server. There is typically no need to call this method, as the object's constructor creates a new thread and runs this object automatically.

Specified by:
  `run` in interface `java.lang.Runnable`