Page 1 of 1

read from socket X for 1 with message Y

Posted: Tue Oct 03, 2017 4:30 am
by jwkuehne
Thinking it would a cinch to upgrade from 6.1.1 to 8.1.6, I am having trouble with sockets again.

Maybe I'm doing something wrong, but in 8.1.6 running in Sierra 10.12.6, trying to read just 1 character doesn't seem to work like it does in 6.1.1. Either I'm an idiot (possible) or nobody is using sockets with the "for count" option, and the engine is busted. I'm worried about these kinds of bugs, because my program controls a 42 ton telescope.

For example, this snippet should read just 1 character. I'm using nc and telnet, and the whole string is placed in dat instead of 1 character. What am I doing wrong? It works in 6.1.1.

Code: Select all

on openstack
   startGUIDER
end openstack

on startGUIDER
  accept connections on port 22401 with message gotGUIDER
end startGUIDER

on gotGUIDER IP, port
   read from socket IP for 1 with message readGUIDER
end gotGUIDER

on readGUIDER IP,dat
   put IP && "DAT" && dat
end readGUIDER

Re: read from socket X for 1 with message Y

Posted: Tue Oct 03, 2017 5:05 am
by shaosean
I know it shouldn't make a difference, but try specifying amount (1 character)

Code: Select all

on gotGUIDER IP, port
   read from socket IP for 1 character with message readGUIDER
end gotGUIDER

Re: read from socket X for 1 with message Y

Posted: Tue Oct 03, 2017 4:38 pm
by MaxV
I wrote this pot about livecode socket of the current version: http://livecodeitalia.blogspot.it/2017/08/sockets.html

There is also the translate button for your language on top left. :D

Re: read from socket X for 1 with message Y

Posted: Tue Oct 03, 2017 6:01 pm
by jwkuehne
I tried adding "for 1 char" but that makes no difference, i.e. in 6.1.1 this sample code really reads just 1 character, and in 8 it now returns more than 1 character if available.

The "until" form *does* work - the read will correctly return up to the match character.

For example, "telnet localhost 22401" and enter "12345." instead of getting the single character "1", you'll get all five characters. Same using "nc" to open the socket and send data.

It's worth mentioning that back in the Metacard days, you could say "for 0" and that would read everything available on the socket and return immediately. That was dropped in Runtime Revolution with the restriction that the count be a positive integer.

Re: read from socket X for 1 with message Y

Posted: Tue Oct 03, 2017 7:20 pm
by FourthWorld
It may be worth trying in a more recent version, and if it still fails then file a bug report. If it turns out not to be a bug, at least you'll get a solution.

Re: read from socket X for 1 with message Y

Posted: Tue Oct 03, 2017 7:59 pm
by jwkuehne
I get the same issue with 8.1.7. I think this problem has been with all of 8, and possibly 7. Thanks for the suggestion. I have a long history of finding socket bugs - the biggest doozy was in a Linux engine, where a socket timeout would cause the graphics to freeze unless you wiggled the mouse.

Re: read from socket X for 1 with message Y

Posted: Thu Oct 05, 2017 3:01 pm
by jwkuehne
This has been confirmed as a bug 20507, introduced in LC 7. I guess I'm the only one on the planet using the "for n" clause. The latest version I can use for Linux/OS X/Windows is 6.1.1.