read from socket X for 1 with message Y

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
jwkuehne
Posts: 27
Joined: Wed Nov 28, 2007 3:12 am

read from socket X for 1 with message Y

Post by jwkuehne » Tue Oct 03, 2017 4:30 am

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
Research Engineer
McDonald Observatory, Texas

shaosean
Posts: 874
Joined: Thu Nov 04, 2010 7:53 am

Re: read from socket X for 1 with message Y

Post by shaosean » Tue Oct 03, 2017 5:05 am

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

MaxV
Posts: 1351
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: read from socket X for 1 with message Y

Post by MaxV » Tue Oct 03, 2017 4:38 pm

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
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

jwkuehne
Posts: 27
Joined: Wed Nov 28, 2007 3:12 am

Re: read from socket X for 1 with message Y

Post by jwkuehne » Tue Oct 03, 2017 6:01 pm

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.
Research Engineer
McDonald Observatory, Texas

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5460
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: read from socket X for 1 with message Y

Post by FourthWorld » Tue Oct 03, 2017 7:20 pm

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.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

jwkuehne
Posts: 27
Joined: Wed Nov 28, 2007 3:12 am

Re: read from socket X for 1 with message Y

Post by jwkuehne » Tue Oct 03, 2017 7:59 pm

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.
Research Engineer
McDonald Observatory, Texas

jwkuehne
Posts: 27
Joined: Wed Nov 28, 2007 3:12 am

Re: read from socket X for 1 with message Y

Post by jwkuehne » Thu Oct 05, 2017 3:01 pm

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.
Research Engineer
McDonald Observatory, Texas

Post Reply

Return to “Mac OS”