testing for socket error

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
daryl
Posts: 47
Joined: Mon Apr 29, 2013 11:43 pm

testing for socket error

Post by daryl » Wed Jun 05, 2013 11:13 pm

Hi Folks,

I read the following:

"If there has been an error connecting to the server the "socketError" message will be sent. (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.)"

in the "How to communicate with other applications using sockets" tutorial at:

http://runrev.screenstepslive.com/s/les ... ng-sockets

but I can not find any examples of how to get at the result to see if there was an error, i.e. bad hostname, no such ipaddr, etc. I also am assuming that if the server should be down the connection attempt would result in a socketTimeout message; is that assumption correct?

Any help figuring this out would be much appreciated.

Thanks,

Daryl

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: testing for socket error

Post by Mark » Wed Jun 05, 2013 11:52 pm

Daryl,

Code: Select all

-- put this into a mouseUp handler for instance
put  "123.45.67.89:80" into mySock
open socket to mySock
put the result into rslt
if rslt is not empty then
  write "helo" to socket mySock
  read from sockey mySock with msg "msgReceived"
else
  beep
  answer error rslt
  -- doesn't matter if socket is already closed
  close socket mySock
end if

-- put this in the same button as the mouseUp handler
-- or higher up the message hierarchy
on socketError theSock,theError
  beep
  answer error theError
end socketError
SocketTimeout is sent if a socket exists but somehow doesn't respond to an open socket, write to socket or read from socket command.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

guylouis
Posts: 26
Joined: Mon Feb 01, 2016 11:45 pm

Re: testing for socket error

Post by guylouis » Thu Feb 11, 2016 1:25 pm

Hi,

What you say in your previous message is not true. It's what it's descibed in Livecode documentation and articles but when you made a socket connection to an existing host which doesn't have opened this port, the result is empty. Same on a server which has opened this port. And the "socketError" is never sent (in the two cases).

Best, Guy

Post Reply

Return to “Internet”