Hi,
I try to create a function in Scriptmaster where I can connect to a TCP Service by using Sockets and get an result back.
The script in Scriptmaster looks like
s = new Socket(host, port);
s.withStreams {
input, output ->
output << "pingn"
result = input.newReader().readLine()
}
s.close()
I always get an error like.
[color:red]groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.net.Socket(java.lang.String, java.lang.String)
what is wrong? why did Scriptmaster not find the java classes or is there an other error?
the same groovy file running local on the machine has no problem
the client side is like
host = "localhost"
port = 8000
s = new Socket(host, port);
s.withStreams { input, output -> output << "pingn" buffer = input.newReader().readLine() println "response = $buffer"}
the server side is like
import java.net.ServerSocket
def server = new ServerSocket(8000)
while(true) {
server.accept { socket ->
println "processing new connection..."
socket.withStreams { input, output ->
def reader = input.newReader()
def buffer = reader.readLine()
println "server received: $buffer"
now = new Date()
output << "echo-response($now) " + buffer + "n"
}
println "processing/thread complete."
}
}
Thanks Markus