Socket server

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
rblackmore245
Posts: 67
Joined: Fri Jun 12, 2015 9:42 am

Socket server

Post by rblackmore245 » Tue Aug 22, 2017 11:29 am

Has anyone managed to write a good multiuser socket server in livecode.

Managed to write one that works great for small amounts of data but having issues with large packets of base64 strings that are split into multiple messages sometimes 30+.

I prefix the data with a username (where its going to ) and who its from and then the server app looks this up against what socket that username is associated with and forwards that data to that socket.

But the issue i'm having is when a lot of data flows through it is slit up into lots of messages and I loose the prefix username and from data.

Anyone ever done this type of app before ?

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

Re: Socket server

Post by MaxV » Tue Aug 22, 2017 1:18 pm

You could prepend the seconds or the millisecods, for human beings are quite unique.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

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

Re: Socket server

Post by FourthWorld » Tue Aug 22, 2017 3:46 pm

How large is that base64 data?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

rblackmore245
Posts: 67
Joined: Fri Jun 12, 2015 9:42 am

Re: Socket server

Post by rblackmore245 » Wed Sep 06, 2017 12:40 pm

It looks like the maximum data length that can flow through livecode sockets is 8192 can anyone confirm this ?

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

Re: Socket server

Post by FourthWorld » Wed Sep 06, 2017 3:27 pm

rblackmore245 wrote:It looks like the maximum data length that can flow through livecode sockets is 8192 can anyone confirm this ?
Where did you read that?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

rblackmore245
Posts: 67
Joined: Fri Jun 12, 2015 9:42 am

Re: Socket server

Post by rblackmore245 » Wed Sep 06, 2017 4:51 pm

just trying to do some tests and sending a large amount of base64data through the socket and it always gets cut at 8192.

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

Re: Socket server

Post by FourthWorld » Wed Sep 06, 2017 5:30 pm

rblackmore245 wrote:just trying to do some tests and sending a large amount of base64data through the socket and it always gets cut at 8192.
It may be useful to see the code. I rarely use sockets directly, but have done a lot of work with HTTP, which LC's libURL handles using the engine's socket calls. It's been rare that I send anything smaller than 8192, often a few MBs.

Which LC version are you using?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

rblackmore245
Posts: 67
Joined: Fri Jun 12, 2015 9:42 am

Re: Socket server

Post by rblackmore245 » Thu Sep 07, 2017 9:22 am

Hi Richard,

The code is nothing complicated just using all the examples from the livecode website more data will flow from the socket but I find that unless you call

"read from socket pSocket with message "messageReceived"" a the end of the function it stops at this limit.

But I suppose this makes sense as it would lock the function if a large data was flowing through the socket waiting for all the packs to be received.

Sorry kinda answered my own question there.

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

Re: Socket server

Post by FourthWorld » Thu Sep 07, 2017 6:04 pm

rblackmore245 wrote:Hi Richard,

The code is nothing complicated just using all the examples from the livecode website more data will flow from the socket but I find that unless you call

"read from socket pSocket with message "messageReceived"" a the end of the function it stops at this limit.

But I suppose this makes sense as it would lock the function if a large data was flowing through the socket waiting for all the packs to be received.

Sorry kinda answered my own question there.
Glad that worked out, but LC should be able to handle both blocking and non-blocking socket comms.

The non-blocking "with message" form is most commonly used, but there are times when blocking is useful. In those cases we need to either read for a specific length, or for a specific delimiter, which may include EOF.

Without knowing whether you used length or a delimiter I can't guess as to what went wrong before, but if non-blocking is what you need you've found the best form anyway.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Internet”