Page 1 of 1
Hiding Socket Errors
Posted: Sun Feb 07, 2016 3:54 pm
by A1Qicks
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?
Re: Hiding Socket Errors
Posted: Sun Feb 07, 2016 4:40 pm
by Klaus
Hi A1Quicks,
that's easy, just script your own "on socketerror" handler
Check the dictionary for "socketerror".
Best
Klaus
Re: Hiding Socket Errors
Posted: Sun Feb 07, 2016 6:35 pm
by A1Qicks
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.
Re: Hiding Socket Errors
Posted: Sun Feb 07, 2016 7:27 pm
by Klaus
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.)
...
Re: Hiding Socket Errors
Posted: Sun Feb 07, 2016 8:57 pm
by A1Qicks
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?
Re: Hiding Socket Errors
Posted: Sun Feb 07, 2016 9:48 pm
by Klaus
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
...
Re: Hiding Socket Errors
Posted: Mon Feb 08, 2016 2:04 pm
by A1Qicks
Fixed it with that and a bit of fiddling - thanks Klaus!