Hiding Socket Errors

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
A1Qicks
Posts: 79
Joined: Sat Dec 26, 2015 10:47 am

Hiding Socket Errors

Post by A1Qicks » Sun Feb 07, 2016 3:54 pm

Simple enough idea - connect to server, read from socket:

open socket field "host" & ":1987" with message "chatConnected"

If the server can't be reached, you get an error back instead. "Error 10061 on Socket" maybe.

However, since this answer isn't built into the code, there's no clear way of adjusting it. But I want a different error message to come up if it can't connect in such a way. Where do I change this?

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Hiding Socket Errors

Post by Klaus » Sun Feb 07, 2016 4:40 pm

Hi A1Quicks,

that's easy, just script your own "on socketerror" handler :D
Check the dictionary for "socketerror".


Best

Klaus

A1Qicks
Posts: 79
Joined: Sat Dec 26, 2015 10:47 am

Re: Hiding Socket Errors

Post by A1Qicks » Sun Feb 07, 2016 6:35 pm

Doesn't seem to be working?

Code: Select all

on socketerror
   answer "Could not connect to the server. Check you have a working internet connection." with "OK"
end socketerror
Still gives me the default error code.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Hiding Socket Errors

Post by Klaus » Sun Feb 07, 2016 7:27 pm

Where did you put that script?

From the dictionary about "open socket", maybe that help:
...
If the socket fails to open due to an error, a socketError message is sent to the object
that attempted to open the socket.
(If the error is due to a problem finding the specified host, the error message is returned in the result,
and no socketError message is sent.)
...

A1Qicks
Posts: 79
Joined: Sat Dec 26, 2015 10:47 am

Re: Hiding Socket Errors

Post by A1Qicks » Sun Feb 07, 2016 8:57 pm

I put it in the card script.

But the error I want to change is that last - a problem finding the specified host. How do I alter that?

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Hiding Socket Errors

Post by Klaus » Sun Feb 07, 2016 9:48 pm

Check the result after (trying) to open the socket:

Code: Select all

...
## ALWAYS use parens when concatenating object names, path/file names and maybe also sockets!
open socket (field "host" & ":1987") with message "chatConnected"
if the result <> EMTPY then
  answer "Your alert here..."
end if
...

A1Qicks
Posts: 79
Joined: Sat Dec 26, 2015 10:47 am

Re: Hiding Socket Errors

Post by A1Qicks » Mon Feb 08, 2016 2:04 pm

Fixed it with that and a bit of fiddling - thanks Klaus!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”