hs.socket
is implemented with CocoaAsyncSocket. CocoaAsyncSocket's tagging features provide a handy way to implement custom protocols.hs.http
is recommended for the real world):hs.socket.setLogLevel()
) :hs.socket.timeout
hs.socket
objects will be created with this timeout value, but can individually change it with the setTimeout
methodhs.socket.parseAddress(sockaddr) -> table or nil
info
method or in hs.socket.udp
's read callback​nil
:<sys/socket.h>
:hs.socket.new([fn]) -> hs.socket object
hs.socket.server(port|path[, fn]) -> hs.socket object
| | -----------------------------------------------------|---------------------------------------------------------------------------------------------------------| | Type | Constructor | | Description | Creates and binds an hs.socket
instance to a port or path (Unix domain socket) for listening | | Parameters |hs.socket:connect({host, port}|path[, fn]) -> self or nil
| | -----------------------------------------------------|---------------------------------------------------------------------------------------------------------| | Type | Method | | Description | Connects an unconnected hs.socket
instance | | Parameters |hs.socket:connected() -> bool
true
if connected, otherwise false
hs.socket:connections() -> number
hs.socket:info() -> table
string
(sockaddr
struct)string
number
string
number
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
string
(sockaddr
struct)string
number
number
string
string
hs.socket:listen(port|path) -> self or nil
| | -----------------------------------------------------|---------------------------------------------------------------------------------------------------------| | Type | Method | | Description | Binds an unconnected hs.socket
instance to a port or path (Unix domain socket) for listening | | Parameters |hs.socket:read(delimiter[, tag]) -> self or nil
hs.socket:receive(delimiter[, tag]) -> self
hs.socket:setCallback([fn]) -> self
nil
or no argument clears the callbackhs.socket:setTimeout(timeout) -> self
hs.socket:startTLS([verify][, peerName]) -> self
false
, allows TLS handshaking with servers with self-signed certificates and does not evaluate the chain of trust. Defaults to true
and omitted if peerName
is suppliedstore.apple.com
. It should match the name in the X.509 certificate given by the remote party. See notes belowpeerName
.The security implications of this are important to understand.Imagine you are attempting to create a secure connection to MySecureServer.com,but your socket gets directed to MaliciousServer.com because of a hacked DNS server.If you simply use the default settings, and MaliciousServer.com has a valid certificate,the default settings will not detect any problems since the certificate is valid.To properly secure your connection in this particular scenario youshould set peerName
to "MySecureServer.com".hs.socket:write(message[, tag][, fn]) -> self