Thin clients talking to each other

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Thin clients talking to each other

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:43 pm

by cnwrbb1 >> Fri, 16 May 2003 9:43:57 GMT

Others may find this solution useful. I'd also be interested if you spot any issues with, or improvements to the approach I have taken.


My client would like two applications to communicate - users run both apps simultaneously as thin client from different databases. The clients need to share search keys to allow searches to be synchronised.

I was keen to avoid any ini file configuration, such as tcp server/ports, shares and directories, etc, as the system is deployed to dozens of environments, so configuration is always problematic. This eliminated solutions based on server clients communicating on behalf of the thin clients, in favour of the thin clients communicating directly on the presentation client PC. Also eliminated is any solution based on polling (e.g. monitoring a directory or calling getMessage) as the network has insufficient capacity.


I discovered that, if client A calls postMessageA (user32.dll), then some of these windows messages are passed to client B as form events. These are:

WM_Paint paint
WM_Char keyPress
WM_LBUTTONDBLCLK dblClick
WM_LBUTTONDOWN mouseDown
WM_LBUTTONUP mouseUp
WM_MBUTTONDBLCLK mouseDown
WM_MBUTTONDOWN mouseDown
WM_MBUTTONUP mouseUp
WM_MOUSEMOVE mouseEnter, mouseMove
WM_RBUTTONDBLCLK mouseDown
WM_RBUTTONDOWN mouseDown
WM_RBUTTONUP contextMenu, mouseUp
WM_SIZE resize
WM_SYSCOLORCHANGE paint
WM_SYSKEYDOWN keyDown, keyDown
WM_SYSKEYUP keyUp, keyUp, keyPress
WM_TIMECHANGE paint

However there aren't many options that I could use to uniquely identify an event as a communication from another client. The wparam parameter passed with WM_CHAR appears as the keyCode for a keypress event, so I settled on the following:

Client A
1. Call findWindow (user32.dll) to get clientB main window handle
2. Write keys to a file %TEMP%\z.tmp, encrypted
3. Call postMessage(hwnd_clientB, WM_CHAR, KEYCODE, null)

I used 1000 for the KEYCODE which hopefully out of the range of keyCodes generated from the keyboard.

Client B
1. In keyPress event, if keyCode = KEYCODE then read keys from file.
2. Clear existing forms and perform new search


Initial testing looks good, and clients for a variety of combinations of environment (e.g. dev, uat, live) will communicate on the same PC without any need to reconfigure.

(Note that the findWindow call relies on a fixed window caption. This also doesn't appear to work for mdi frames - I didn't spend time investigating why, but got round these issues by creating another child form dedicated to the purpose, which has a fixed caption, is invisible and has zero height and width).

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Thin clients talking to each other

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:43 pm

by allistar >> Sat, 17 May 2003 2:34:09 GMT

Hi there,
It's an intersting solution. It's a pain that we have no way of getting access to the messge queue for a window in Jade, that way we could create our own events (WM_USER + 1, WM_USER + 2 etc.) which we could then catch in Jade and act on.

An interesting thing I got working is that in an external application (Jade or not) if you know the hwnd of a Label in Jade, you can directly change the text of that label from within the external application. The unfortunate thing is that Jade is unaware of the change, so accessing label.caption returns the un-altered value. There are other controls in Jade you can directly send messages to, as you have discovered.

A solution on Jades part would be be to have a new control event called "otherEvent" that gets called if an event number >= WM_USER is sent to the control. That way we could catch such events easily and process them, without require any file access.

Regards,
Allistar.

------------------------------------------------------------------
Allistar Melville
Software Developer, Analyst allistar@silvermoon.co.nz
Auckland, NEW ZEALAND

Silvermoon Software
Specialising in JADE development and consulting
Visit us at: http://www.silvermoon.co.nz
*NEW* Simple web access to Jade at: www.silvermoon.co.nz/jhp/html ------------------------------------------------------------------

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Thin clients talking to each other

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:43 pm

by cnwrbb1 >> Mon, 19 May 2003 15:42:13 GMT

By complete coincidence, I was talking to another developer the next day who has a serial printer with an eject button. Because his thin client cannot efficiently poll the button state, and it cannot respond to the user event that is generated, he resorted to writing an activeX control to poll the button state. Allistar's suggested 'otherEvent' solution would have avoided this extra effort.


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 16 guests