PowerSystem Posted June 30, 2010 Posted June 30, 2010 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
Jesse Barnum Posted June 30, 2010 Posted June 30, 2010 The problem is that ScriptMaster treats all input values from FileMaker as text / Strings. There is no Socket constructor that takes two strings, it expects a string and an integer. The solution is simply to use Integer.valueOf( port ) to convert it to an Integer value. You'll see examples of this in several other ScriptMaster modules that expect numeric inputs.
PowerSystem Posted July 1, 2010 Author Posted July 1, 2010 Thank you very much for the advice, now it works fine for all the code now looks like s = new Socket(host, Integer.valueOf( port )); s.withStreams { input, output -> output << "pingn" result = input.newReader().readLine() } s.close() Markus
Recommended Posts
This topic is 5278 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now