Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Windows / Sockets - Connecting to a 3rd Party Process

Author
Message
Yeshu777
4
Years of Service
User Offline
Joined: 26th Feb 2020
Location: Cymru
Posted: 8th Jul 2023 19:56
Hi Everyone,

Looking for some genuine help - regarding sockets - and tring to communicate with a 3rd Party Windows Process.

Basically, I'm trying to control a motor.

I created a small test app in AGK.. which is working to a point.

Once the Process has started I need to wait for it to initialise the hardware / motor etc.. and retrun an "idle" state ( a string )

1. I start the 3rd Party API process.. RunApp ( "motor_controller.exe", " " ) - no parameters are passed..

2. I setup a socket - 127.0.0.1 : 3300 - ( Local Host on port 3300 ) connects to the process fine ( tested by commenting out the RunApp etc )

3. Once connected every second or so.. try to read a string from the socket ( merely just to display some communication )..

I test for GetSocketBytesAvailable from Socket before reading the string..



But only when I terminate the 3rd Party Windows Process ( via Task Manager ) - do I receive anything from the socket.

In discussion, the 3rd Party programmer has said the socket should be event driven, not checked every second.

Any pointers would help!

Thanks
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 9th Jul 2023 01:36
without seeing the code behind the 3rd party sender app its hard to really tell whats going on ....

but ... GetSocketString it very particular in how it receives its string from non AppGameKit connections, the data buffer must be the byte size of the string plus 4 bytes, the first 4 bytes of the of the data buffer must be the length of the string and the rest of the buffer the string content, so without seeing how the sender app if formatting the buffer .... try reading raw bytes and see what you get "GetSockeyByte"

Event Driven ....... you receive bytes and and react ... thats an event, you dont know a event has occurred unless you ... Humm, check for it!, event driven frameworks still check for events in the background its just hidden from the user.

How does the motor_controller.exe communicate with the motor ... can you not connect directly to it? , serial?, usb? wi-fi?

any documentation with motor_controller.exe?
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Yeshu777
4
Years of Service
User Offline
Joined: 26th Feb 2020
Location: Cymru
Posted: 9th Jul 2023 02:37
Hi,

Thanks for the reply. Have not long resolved it.

Yes, it's the GetSocketString() that's an issue.. the 3rd party API is not sending the length in the first 4 bytes, so it's causing it to hang until closed.

Using GetSocketBytesAvailable & then GetSocketByte - then converting the bytes to display the messages works.. at least so I can ensure the board has initialised and I can then send commands.

My intention was to talk directly to the motor via a COM port - but was informed the preferred method was to socket to the API let it handle to low level comms ( for backwards compatibility ).

Again thanks for the input, really appreciated.

Y



Yeshu777
4
Years of Service
User Offline
Joined: 26th Feb 2020
Location: Cymru
Posted: 2nd Aug 2023 09:48
Hi All,

An additional piece of information..

SendSocketString( ) sends a packet to the socket in the following format...

[ 20 byte packet header ]
[ 4 byte size ]
[ message string ]

AGK sends this packet with the [ 4 byte size ] as Little Endian, my 3rd party API was expecting it to be Big Endian, so it would cause the 3P API to hang / 100% cpu usage.

If you are experiencing such an issue, this is more than likely the probable cause.



Login to post a reply

Server time is: 2024-05-06 09:44:44
Your offset time is: 2024-05-06 09:44:44