Hiding Socket Errors
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Hiding Socket Errors
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?
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
Hi A1Quicks,
that's easy, just script your own "on socketerror" handler
Check the dictionary for "socketerror".
Best
Klaus
that's easy, just script your own "on socketerror" handler
Check the dictionary for "socketerror".
Best
Klaus
Re: Hiding Socket Errors
Doesn't seem to be working?
Still gives me the default error code.
Code: Select all
on socketerror
answer "Could not connect to the server. Check you have a working internet connection." with "OK"
end socketerror
Re: Hiding Socket Errors
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.)
...
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
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?
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
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
Fixed it with that and a bit of fiddling - thanks Klaus!