Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The code compiles using the examples using spm and MacOS X #3

Closed
TyrfingMjolnir opened this issue Jan 8, 2019 · 3 comments
Closed

Comments

@TyrfingMjolnir
Copy link

TyrfingMjolnir commented Jan 8, 2019

swift build && ./.build/x86_64-apple-macosx10.10/debug/PerfectTemplate

I have tried just about all the examples on the page, however all of them behave exactly the same as typing: echo -n and hitting enter in the terminal. I know FileMaker is set up correctly as I can use both curl and FX.php against the FileMaker server.

$ cat Sources/PerfectTemplate/main.swift
import PerfectHTTP
import PerfectHTTPServer
import PerfectSMTP
import PerfectFileMaker

let fms = FileMakerServer( host: "127.0.0.1", port: 8180, userName: "username", password: "password" )

print( fms )

fms.layoutInfo( database: "db", layout: "layout {
	result in
	guard let layoutInfo = try? result() else {
                print( "No result" )
		return // error
	}
	let fieldsByName = layoutInfo.fieldsByName
	for ( name, value ) in fieldsByName {
		print( "Field \( name ) = \( value )" )
	}
}

Building and running the code:

$ swift build && ./.build/x86_64-apple-macosx10.10/debug/PerfectTemplate
warning: PackageDescription API v3 is deprecated and will be removed in the future; used by package(s): libxml2
Compile Swift Module 'PerfectTemplate' (1 sources)
Linking ./.build/x86_64-apple-macosx10.10/debug/PerfectTemplate
FileMakerServer(host: "filemaker.lan.domain.tld", port: 80, userName: "username", password: "password" )
devMB15R:PerfectTemplate user$
$ cat Package.swift
// swift-tools-version:4.0

import PackageDescription
let projectName = "PerfectTemplate"
let package    = Package(
	name: projectName,
	products: [
		.executable(name: "PerfectTemplate", targets: ["PerfectTemplate"])
	],
	dependencies: [
		.package(url: "https://github.com/PerfectlySoft/Perfect-HTTPServer.git", from: "3.0.0" ),
		.package(url: "https://github.com/PerfectlySoft/Perfect-FileMaker.git", from: "3.0.0" ),
		.package(url: "https://github.com/PerfectlySoft/Perfect-SMTP.git", from: "3.0.0" ),
	],
	targets: [
		.target( name: projectName,
     dependencies: [
       "PerfectHTTPServer",
       "PerfectSMTP",
       "PerfectFileMaker",
     ]
   )
	]
)

also tried to set up netcat to no avail

let fms = FileMakerServer( host: "127.0.0.1", port: 8180, userName: "username", password: "password" )

And listening as below:

nc -l -p 8180

No output.

If there was errors I could correct myself, when there is apathy I'm having a hard time.

@TyrfingMjolnir
Copy link
Author

TyrfingMjolnir commented Jan 9, 2019

Sometimes when I think a bit and read the actual code; opposed to copy / paste and expect it to work, I understand the examples are incomplete; adding

let a = fms
print( a )

executes; still does not give any reply from FileMaker 16 Server, works fine with netcat however.

I wrote this short note to give you a quick start

https://gist.github.com/TyrfingMjolnir/ec677d62872b4ed9302f5593e4cbfb85

@TyrfingMjolnir
Copy link
Author

TyrfingMjolnir commented Jan 9, 2019

Trying again on another server and workstation; this is the query generated by PerfectFilerMaker, exposed by netcat:

$ nc -l 8081
POST /fmi/xml/fmresultset.xml HTTP/1.1
Host: 127.0.0.1:8081
Authorization: Basic d2ViOndlYg==
Accept: */*
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Content-Length: 8

-dbnames

@kjessup
Copy link
Member

kjessup commented Jan 11, 2019

Hello - Performing any action with Perfect-FileMaker is an asynchronous activity. The way your main.swift looks structured there, the process will launch, issue the request and then run off the end end exit; so the "result" callback will never be called.

To experiment and see if this is indeed the cause, put a sleep at the end. Like so:

https://gist.github.com/kjessup/f95830dd6572255ebbb1c6799eaa4e41

You should then see the expected request output.

@kjessup kjessup closed this as completed Apr 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants