Re: Sockets (again)

2023-04-09 Thread Tom Glod via use-livecode
Thanks guys, this was a very insightful thread.

On Wed, Apr 5, 2023 at 1:31 PM Mark Wieder via use-livecode <
use-livecode@lists.runrev.com> wrote:

> On 4/5/23 08:13, Bob Sneidar via use-livecode wrote:
> > Thanks Phil. Yes I learned the hard way with my SQL Agent to
> base64encode anything over sockets. And yes I do append a numtochar(13)
> coming and going and strip it off before decoding and read until
> numToChar(13). I don't use cr because I am uncertain how each OS platform
> treats it. The Server Agent could be running on anything in the future.
>
> If you're already base64encoding the text you might consider a different
> end character than numtochar(13). For instance, numtochar(3) is already
> defined as "End of Text". That should eliminate or at least reduce any
> cross-platform issues you might run into.
>
> https://www.ascii-code.com/
>
> --
>   Mark Wieder
>   ahsoftw...@gmail.com
>
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Sockets (again)

2023-04-05 Thread Mark Wieder via use-livecode

On 4/5/23 08:13, Bob Sneidar via use-livecode wrote:

Thanks Phil. Yes I learned the hard way with my SQL Agent to base64encode 
anything over sockets. And yes I do append a numtochar(13) coming and going and 
strip it off before decoding and read until numToChar(13). I don't use cr 
because I am uncertain how each OS platform treats it. The Server Agent could 
be running on anything in the future.


If you're already base64encoding the text you might consider a different 
end character than numtochar(13). For instance, numtochar(3) is already 
defined as "End of Text". That should eliminate or at least reduce any 
cross-platform issues you might run into.


https://www.ascii-code.com/

--
 Mark Wieder
 ahsoftw...@gmail.com


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Sockets (again)

2023-04-05 Thread Bob Sneidar via use-livecode
Thanks Phil. Yes I learned the hard way with my SQL Agent to base64encode 
anything over sockets. And yes I do append a numtochar(13) coming and going and 
strip it off before decoding and read until numToChar(13). I don't use cr 
because I am uncertain how each OS platform treats it. The Server Agent could 
be running on anything in the future. 

I also instituted a debugging log and determined the File Server Agent is 
getting the payload and sending the result back, but for whatever reason the 
client side is not getting the result. It may be that I have to initiate some 
kind of delay on the server side because the assumption has to be that the 
reply is getting sent before the client starts listening. 

Bob S


> On Apr 4, 2023, at 20:06, Phil Davis via use-livecode 
>  wrote:
> 
> Bob -
> 
> Don't use EOF. It's broken since forever ago.
> 
> I've done both of the following methods with success:
> 
> -- either --
> 
> End your data stream with a CR, and then on the receiving end "read from 
> socket XYZ for 1 line". This assumes that the data stream itself doesn't 
> contain any CRs. I normally base64-encode the data stream, then replace CR 
> with empty in the encoded string. This doesn't interfere with base64Decoding 
> on the receiving end - it'll still work fine.
> 
> -- or --
> 
> Make line 1 of your data stream an integer that is the number of bytes in 
> line 2 of your data stream
> Make line 2 of your data stream the data you want to send
> 
> Then on the receiving end, do a two-step:
> - read from socket XYZ for 1 line
> - put it into tDataLength
> - read from socket XYZ for tDataLength bytes
> 
> 
> That's all I got :-)
> Phil Davis
> 
> 
> 
> On 4/4/23 1:47 PM, Bob Sneidar via use-livecode wrote:
>> I have sockets working in my File Server Agent, but only using non-blocking 
>> calls, that is using "with message". Removing the "with message" bit does 
>> not return any response from the server agent.
>> 
>> For instance I send a payload using
>> write payload to socket tSocket with message "messageReceived"
>> The messageReceived handler gets triggered, and I can then
>> read from socket tSocket until EOF -- or other delimiter
>> it will then contain the response from the File Server Agent.
>> 
>> If however I use
>> write payload to socket tSocket -- blocking
>> read from socket tSocket until EOF -- or some other delimiter doesn't matter
>> 
>> the call times out and nothing ends up in the it or result variables.
>> 
>> I can (and have) made the non-blocking method work, but that means I have to 
>> send all the files I want to transfer all at once, because if I send them 
>> one at a time, I need to know if the last transfer succeeded before 
>> continuing.
>> 
>> Does anyone have an example of a blocking socket server? The example in 
>> Livecode Lessons really only focuses on non-blocking calls.
>> 
>> Bob S
>> 
>> 
>> ___
>> use-livecode mailing list
>> use-livecode@lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription 
>> preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
> 
> -- 
> Phil Davis
> (503) 307-4363
> 
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Sockets (again)

2023-04-04 Thread Phil Davis via use-livecode

Bob -

Don't use EOF. It's broken since forever ago.

I've done both of the following methods with success:

-- either --

End your data stream with a CR, and then on the receiving end "read from 
socket XYZ for 1 line". This assumes that the data stream itself doesn't 
contain any CRs. I normally base64-encode the data stream, then replace 
CR with empty in the encoded string. This doesn't interfere with 
base64Decoding on the receiving end - it'll still work fine.


-- or --

Make line 1 of your data stream an integer that is the number of bytes 
in line 2 of your data stream

Make line 2 of your data stream the data you want to send

Then on the receiving end, do a two-step:
- read from socket XYZ for 1 line
- put it into tDataLength
- read from socket XYZ for tDataLength bytes


That's all I got :-)
Phil Davis



On 4/4/23 1:47 PM, Bob Sneidar via use-livecode wrote:

I have sockets working in my File Server Agent, but only using non-blocking calls, that is using 
"with message". Removing the "with message" bit does not return any response 
from the server agent.

For instance I send a payload using
write payload to socket tSocket with message "messageReceived"
The messageReceived handler gets triggered, and I can then
read from socket tSocket until EOF -- or other delimiter
it will then contain the response from the File Server Agent.

If however I use
write payload to socket tSocket -- blocking
read from socket tSocket until EOF -- or some other delimiter doesn't matter

the call times out and nothing ends up in the it or result variables.

I can (and have) made the non-blocking method work, but that means I have to 
send all the files I want to transfer all at once, because if I send them one 
at a time, I need to know if the last transfer succeeded before continuing.

Does anyone have an example of a blocking socket server? The example in 
Livecode Lessons really only focuses on non-blocking calls.

Bob S


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode



--
Phil Davis
(503) 307-4363


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Sockets (again)

2023-04-04 Thread Bob Sneidar via use-livecode
I have sockets working in my File Server Agent, but only using non-blocking 
calls, that is using "with message". Removing the "with message" bit does not 
return any response from the server agent. 

For instance I send a payload using 
write payload to socket tSocket with message "messageReceived" 
The messageReceived handler gets triggered, and I can then 
read from socket tSocket until EOF -- or other delimiter
it will then contain the response from the File Server Agent. 

If however I use 
write payload to socket tSocket -- blocking
read from socket tSocket until EOF -- or some other delimiter doesn't matter

the call times out and nothing ends up in the it or result variables. 

I can (and have) made the non-blocking method work, but that means I have to 
send all the files I want to transfer all at once, because if I send them one 
at a time, I need to know if the last transfer succeeded before continuing. 

Does anyone have an example of a blocking socket server? The example in 
Livecode Lessons really only focuses on non-blocking calls. 

Bob S


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


RE: Sockets (again)

2020-06-29 Thread Ralph DiMola via use-livecode
Bob,

I think you are doing the write too soon.
On the open socket command add "with message "MyConnectionAccepted"
Do the write in the MyConnectionAccepted handler.

Ralph DiMola
IT Director
Evergreen Information Services
rdim...@evergreeninfo.net


-Original Message-
From: use-livecode [mailto:use-livecode-boun...@lists.runrev.com] On Behalf Of 
Bob Sneidar via use-livecode
Sent: Monday, June 29, 2020 5:42 PM
To: How to use LiveCode
Cc: Bob Sneidar
Subject: Sockets (again)

Hi all. 

I’m trying to get sockets working. The host is working, but I am not getting 
the message to trigger. Here’s the basic code: 

on mouseUp
   put "test" into tPayLoad
   open socket to "localhost:8085"
   write tPayload to socket "localhost:8085"
end mouseUp

-- socket handlers
on acceptConnections
  accept connections on port 8085 with message "ConnectionMade"
end acceptConnections

on ConnectionMade pIPAddress
  read from socket pIPAddress with message "dataReceived"
end ConnectionMade

on dataReceived pSocket
put pSocket
   


ConnectionMade gets called, but dataReceived does not. 

Bob S

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Sockets (again)

2020-06-29 Thread doc hawk via use-livecode
I have a pair at http://dochawkbk.com/lcImages/ 
 of master and slave stacks to talk to one 
another.

They're meant to be compiled.

They're probably 5.x stacks . . . I haven’t looked at them for a while.

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Sockets (again)

2020-06-29 Thread Bob Sneidar via use-livecode
Hi all. 

I’m trying to get sockets working. The host is working, but I am not getting 
the message to trigger. Here’s the basic code: 

on mouseUp
   put "test" into tPayLoad
   open socket to "localhost:8085"
   write tPayload to socket "localhost:8085"
end mouseUp

-- socket handlers
on acceptConnections
  accept connections on port 8085 with message "ConnectionMade"
end acceptConnections

on ConnectionMade pIPAddress
  read from socket pIPAddress with message "dataReceived"
end ConnectionMade

on dataReceived pSocket
put pSocket
   


ConnectionMade gets called, but dataReceived does not. 

Bob S

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode