polling only on socket, or can there be a trigger?

Phil Davis revdev at pdslabs.net
Sat May 9 00:37:52 EDT 2015


Hi Dr H,

There are two basic approaches you can take, which you probably know but 
I'll lay them out for clarity. And maybe you're already doing one of 
them - from what you've told us, I couldn't tell.


-- #1: handle the connection in an "inline" manner -----------

on openStack -- or your message of choice
     accept connections on port 8010 with message "newClient"
end openStack


command newClient pSocket
     -- read all the incoming data
     put empty into tData
     repeat -- the belt-and-suspenders approach
         read from socket pSocket until empty
         if it is empty
         then exit repeat
         else put it after tData
     end repeat

     -- do whatever
     put processData(tData) into tResponse

     -- write a response
     write tResponse to pSocket

     -- say goodbye
     close socket pSocket
end newClient




-- #2: handle the connection in a message-driven manner ---

on openStack
     accept connections on port 8010 with message "newClient"
end openStack


command newClient pSocket
     -- read all the incoming data
     read from socket pSocket until empty with message "newData"
end newClient


command newData pSocket, pData
     -- do whatever
     put processData(pData) into tResponse

     -- write a response
     write tResponse to pSocket with message "newWrite"
end newData


command newWrite pSocket
     close socket pSocket
end newWrite


----------------------------------

At least one of these approaches should serve your needs.

Phil Davis



On 5/8/15 12:16 PM, Dr. Hawkins wrote:
> On Fri, May 8, 2015 at 8:05 AM, Dr. Hawkins <dochawk at gmail.com> wrote:
>
>> It does???
>>
>> I guess I'm misunderstanding the docs, then--I though it would stay at
>> that line, rather than going on to execute.  I'll have to experiment some
>> more.
>>
> Now I'm even more confused.
>
> I accept sockets on 8010 with message "newClient"
>
> When I connect from another program (I'm actually running the slave under
> 5.5 so I can debug separately), it shows that the connection is "
> 127.0.0.1:52572"
>
> A subsequent line
>
> read from socket clAdr with message "dhbkProcScktDat"
>
> results in livecode hanging with a beachball forever.  If I comment that
> out, write a message from the other, and
>
> read from socket "127.0.0.1:8010" until empty
>
> I'm told that the socket is not open. I then try
>
> read from socket "127.0.0.1:52572" until empty
>
> and get an empty result back (after writing from the other).

-- 
Phil Davis





More information about the use-livecode mailing list