open socket | |||||||||||||||||||||||||
Type | command | ||||||||||||||||||||||||
Dictionary | LCS | ||||||||||||||||||||||||
Library | LiveCode Script | ||||||||||||||||||||||||
Syntax |
| ||||||||||||||||||||||||
Associations | ssl & encryption | ||||||||||||||||||||||||
Summary | Establishes either a TCP or UDP communications socket between your system and another system. | ||||||||||||||||||||||||
Introduced | 1.0 | ||||||||||||||||||||||||
Changes | (6.7) Added the "with verification for host" variant. (9.0) Added the ability to specify the local host and port. | ||||||||||||||||||||||||
OS | mac, windows, linux, ios, android | ||||||||||||||||||||||||
Platforms | desktop, server, mobile | ||||||||||||||||||||||||
Parameters |
| ||||||||||||||||||||||||
Example |
| ||||||||||||||||||||||||
Values |
| ||||||||||||||||||||||||
Related | Property: defaultNetworkInterface Message: socketTimeout Command: accept, post, wait Glossary: TCP, UDP, command, socket, Standalone Application Settings, command, LiveCode custom library, datagram Library: SSL & Encryption library | ||||||||||||||||||||||||
Security | network | ||||||||||||||||||||||||
Description | Use the open socket command to open a connection to another system on the Internet (or another IP network) to get and send data. When a connection is made, the open socket command creates a new socket that can be used to communicate with the other system. The handler continues executing while the connection is being established. If you use the write to socket command while the connection is opening, the data is buffered and is sent to the host as soon as the connection is made. Use the open datagram socket form if you want to send a connectionless UDP datagram instead of opening a socket. If you specify a callbackMessage, the message is sent to the object whose script contains the open socket command, as soon as the connection is made. The first parameter pf this message is the host and port number of the socket. Use a callbackMessage to trigger actions (such as reading from the socket) that must wait until the connection has been established. (To pause the handler that contains the open socket command until the callbackMessage is received, use the wait for messages form of the wait command.) UDP/datagram sockets are not supported by SSL. When connecting to a remote peer, the client verifies the servers certificate during the handshake process and verifies it against a list of certificates. You can specify a list of root CA to verify against using the sslcertificates property (see sslurlloader sample). The sslcertficates property takes a return delimited list of files or folders. In addition you can place system wide certfificates in System/Library/OpenSSL/certs. The most common CAs such as verisign can be found in the file root.pem. If a verificationhostname is specified, the socket will be verified against that verificationhostname rather than the host. An example of this is when you want to create a secure connection with a host while tunnelling through a proxy. Specifying the final host allows LiveCode to verify the socket against that host, rather than the proxy server. If 'without verification' is specified then server credentials are not authenticated, and any connection is accepted.
For technical information about the numbers used to designate standard ports, see the list of port numbers at http://www.iana.org/assignments/port-numbers, in particular the section titled "Well Known Port Numbers".
(4.5) The open socket command no longer blocks on DNS resolution. Instead, if resolution is required the command will return immediately and the DNS lookup will happen in the background. If resolution fails, then a socketError message is sent in the same was as if connection fails. For applications using hostNameToAddress directly, its syntax has been augmented:
If the callback parameter is specified then the call will return immediately and upon completion of the lookup, the callback will be invoked with the resolved address as a parameter. |