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.

AppGameKit Classic Chat / [SOLVED] AGK hanging while reading GetSocketString?

Author
Message
Carharttguy
7
Years of Service
User Offline
Joined: 8th Jul 2016
Location: Belgium
Posted: 22nd Mar 2021 21:46 Edited at: 23rd Mar 2021 08:25
Hello

I'm sending a string from a non AppGameKit app to an AppGameKit app. It's semi working now.
The connection is made, but when the string is send, the AppGameKit app hangs, until I close the connection (from the non AppGameKit app)
Then the string is showed.

Why does the app hang? I think AppGameKit expects me to manually clear the buffer after GetSocketString (I think it hangs because it's constantly reading the string) however I cannot find a command to clear the buffer.

See my very simple code attached, does anyone see what I'm doing wrong here?

Thanks!



Edit: This is the ByteArray I'm sending: 00 00 00 04 54 65 73 74
The first 4 bytes indicate the length (4) and then an UTF-8 string "Test". But the string receives just fine, but only after I kill the connection (and the AppGameKit app stops hanging)

Thanks for any insight.

The author of this post has marked a post as an answer.

Go to answer

Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 23rd Mar 2021 09:10 Edited at: 23rd Mar 2021 09:19
Quote: "If there are 4 or more bytes waiting to be read then this command will wait until the entire string has been received before returning. "


From here:
https://www.appgamekit.com/documentation/Reference/Multiplayer/GetSocketString.htm

This may be your case
For further testing, I would recommend you to get everything byte by byte into a buffer array.
Like:



Keep us updated

Carharttguy
7
Years of Service
User Offline
Joined: 8th Jul 2016
Location: Belgium
Posted: 23rd Mar 2021 10:25
Hi Jack, Thanks for your respons.

It seems that this is indeed what's happening. The buffer only receives 7 bytes. While this log from Wireshark show that the 8 bytes are actually send.
See image here:


The odd thing is that AppGameKit only registers 7, and keeps waiting for the 8 byte. I don't know why AppGameKit doesn't register the last byte, and only processes this after a disconnect.
Could this be a bug?
Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 23rd Mar 2021 11:09 Edited at: 23rd Mar 2021 11:12
This post has been marked by the post author as the answer.
Can you pinpoint it further?
There may be something going on with the GetSocketString command, we don't know yet. (Ive always used bytewise communication and had never a fault)
Endianness is always sort of scary, when implementing a protocol
https://en.wikipedia.org/wiki/Endianness



Try to consider to build another socket sender that you pack and send a string to your current client then look what wireshark says

Carharttguy
7
Years of Service
User Offline
Joined: 8th Jul 2016
Location: Belgium
Posted: 23rd Mar 2021 12:43 Edited at: 23rd Mar 2021 12:55
Thanks again for thinking with me.

I used another server app named Hercules (https://www.hw-group.com/software/hercules-setup-utility) as TCP server instead of my own. This one produces the exact same result.
I

AGK hangs and continues only after a disconnect (and showing the expected result)
I can also use pure byte communication and use the Chr() function to decode the bytes to string. But that doesn't solve the real problem ofcourse.

I also found another weird thing, replacing the first 4 bytes from 00 00 00 04 to 00 00 00 03 doesn't change a thing. I would expect AppGameKit to print the first 3 characters and let the last one on the buffer. But it doesn't make any difference, the app hangs, and then shows the full 4 characters if the server closes the connection.

I also mailed Paul for this issue. Maybe I'm doing something very stupid here and the solution is easy, but just maybe I just found a real bug
Carharttguy
7
Years of Service
User Offline
Joined: 8th Jul 2016
Location: Belgium
Posted: 23rd Mar 2021 13:17
I searched more on Endianness, I tought it couldn't be the problem because the string came trough as Test and not as tseT. But that's not how it works!
So sending 04 00 00 00 instead of 04 00 00 00 worked. It seems that I was actually sending 67108864 instead of 4, so the app was waiting for the other 67108860 bytes to arrive

Maybe it wouldn't be a bad idea to mention this in the docs

Thanks a lot for your help Jack!

Login to post a reply

Server time is: 2024-04-18 07:47:04
Your offset time is: 2024-04-18 07:47:04