Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

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.

  • Author

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

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.