See text returned from a tsNetCustom TCP call

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
webmaster
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 83
Joined: Mon May 09, 2011 3:01 pm

See text returned from a tsNetCustom TCP call

Post by webmaster » Wed Oct 15, 2025 11:31 pm

When I issue a TCP call using tsNetCustom, the server sends a response as text. How can I put the returned text into a variable so it can be shown either as an "answer" (dialog box) or set as the text of a display field?

Klaus
Posts: 14247
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: See text returned from a tsNetCustom TCP call

Post by Klaus » Thu Oct 16, 2025 12:10 pm

I never used tsNetCustom, but this is a function, so doesn't it (or "the result") return something useful?
Or the params your "callback" handler comes with? In case you use a callback message.

stam
Posts: 3134
Joined: Sun Jun 04, 2006 9:39 pm

Re: See text returned from a tsNetCustom TCP call

Post by stam » Sat Oct 18, 2025 11:10 pm

webmaster wrote:
Wed Oct 15, 2025 11:31 pm
When I issue a TCP call using tsNetCustom, the server sends a response as text. How can I put the returned text into a variable so it can be shown either as an "answer" (dialog box) or set as the text of a display field?
I'm not familiar with tsNetCustom, but looking the documentation:
The tsNetCustom function returns empty on success. On error, the return value will be a string containing the error starting with "tsneterr:".
This basically means it returns errors if they are present as as string, and you run this comment but putting it into a variable, eg:

Code: Select all

get tsNetCustom (parameters) --> the returned value is in the 'it' variable
// or
put tsNetCustom (parameters) into tError --> the returned value is in the tError variable.

I'm guessing this is not what you're after though... I'm guessing you want to use data that may be returned.

In that case you'd probably needs to use the callback function that manages this. for example in the code below, pCallBack is the name of the handler to call on completion.

Code: Select all

tsNetCustom(<pConnectionID>, <pURL>, <pRequest>, <pHeaders>, <pCallback>)
Your callback handler could be something like this:

Code: Select all

on transferComplete pConnectionID, pResult, pData, pBytesTransferred
  if pResult is not 200 then -- 200 is the HTTP success code
    -- Handle error cases here
    answer "Error: " & pResult
  else
    -- Process the returned data
    put pData into field "Output"
  end if
  
  -- Clean up the connection
  tsNetCloseConn pConnectionID
end transferComplete
I rarely have a cause to use tsNet handlers to take the above with a pinch of salt...

Post Reply