Qore Programming Language Reference Manual
0.8.11.1
|
The Socket class allows Qore programs safe access to network sockets. More...
Public Member Functions | |
Socket | accept () |
Accepts connections on a listening socket. More... | |
*Socket | accept (timeout timeout_ms) |
Accepts connections on a listening socket (see Socket::listen()) accepting a timeout value with a millisecond resolution. More... | |
Socket | acceptSSL () |
Accepts connections on a listening socket and attempts to negotiate a TLS/SSL connection. More... | |
*Socket | acceptSSL (timeout timeout_ms) |
Accepts connections on a listening socket and attempts to negotiate a TLS/SSL connection accepting a timeout value with a millisecond resolution. More... | |
int | bind (string str, softbool reuseaddr=False) |
Opens and binds the socket to a port, interface and port (if the $bind_to string has a format "host:port"), or UNIX domain socket file. More... | |
int | bind (int port, softbool reuseaddr=False) |
Opens and binds the socket to an INET port on all interfaces. More... | |
nothing | bindINET (*string iface, *softstring service, softbool reuseaddr=False, softint family=AF_UNSPEC, softint socktype=SOCK_STREAM, softint protocol=0) |
Opens and binds the socket to the given IPv4 or IPv6 interface (or if no interface is given, then to all interfaces on the local system) and port (the port number will be derived from the service name if a numeric port number is not given) More... | |
nothing | bindUNIX (string path, softint socktype=SOCK_STREAM, softint protocol=0) |
Opens and binds the socket to the given UNIX domain socket file as given by the filename argument. If any errors occur, an exception is thrown. More... | |
clearStats () | |
Clears performance statistics. More... | |
nothing | clearWarningQueue () |
Removes any warning Queue object from the Socket. More... | |
int | close () |
Closes an open socket. More... | |
nothing | connect (string target, timeout timeout_ms=-1) |
Connects to a remote port (if the string has a format "host:port") or UNIX domain socket file with an optional timeout value with a millisecond resolution. More... | |
nothing | connectINET (string host, softstring service, timeout timeout_ms=-1, softint family=AF_UNSPEC, softint socktype=SOCK_STREAM, softint protocol=0) |
Connects to the given host and port with an optional timeout value with a millisecond resolution. More... | |
nothing | connectINETSSL (string host, softstring service, timeout timeout_ms=-1, softint family=AF_UNSPEC, softint socktype=SOCK_STREAM, softint protocol=0) |
Connects to the given host and port and attempts to establish a TLS/SSL connection; accepts an optional timeout value with a millisecond resolution. More... | |
nothing | connectSSL (string target, timeout timeout_ms=-1) |
Connects to a remote socket and attempts to establish a TLS/SSL connection; accepts an optional timeout value with a millisecond resolution. More... | |
nothing | connectUNIX (string path, softint socktype=SOCK_STREAM, softint protocol=0) |
Connects to a UNIX domain socket file. More... | |
nothing | connectUNIXSSL (string path, softint socktype=SOCK_STREAM, softint protocol=0) |
Connects to the given UNIX domain socket file and attempts to establish a TLS/SSL connection. More... | |
constructor () | |
Creates the socket object. More... | |
copy () | |
Creates a new Socket object, not based on the source being copied. More... | |
string | getCharset () |
Returns the character encoding for the socket. More... | |
string | getEncoding () |
Returns the character encoding for the socket. More... | |
bool | getNoDelay () |
Returns the TCP_NODELAY setting for the socket. More... | |
hash | getPeerInfo (bool host_lookup=True) |
Returns a hash of information about the remote end for connected sockets. More... | |
int | getPort () |
Returns the port number of the socket for INET sockets. More... | |
int | getRecvTimeout () |
Returns the receive timeout socket option value as an integer in milliseconds. More... | |
*string | getSSLCipherName () |
Returns the name of the cipher for an encrypted connection or NOTHING if a secure connection has not been established. More... | |
*string | getSSLCipherVersion () |
Returns the version string of the cipher for an encrypted connection or NOTHING if a secure connection has not been established. More... | |
int | getSendTimeout () |
Returns the send timeout socket option value as an integer in milliseconds. More... | |
int | getSocket () |
Returns the socket file descriptor number. More... | |
hash | getSocketInfo (bool host_lookup=True) |
Returns information about the local socket as a hash. More... | |
hash | getUsageInfo () |
Returns performance statistics for the socket. More... | |
bool | isDataAvailable (timeout timeout_ms=0) |
Returns True or False depending on whether there is data to be read on the socket. More... | |
bool | isOpen () |
Returns True if the socket is open. More... | |
bool | isSecure () |
Returns True if the connection is a secure TLS/SSL connection. More... | |
bool | isWriteFinished (timeout timeout_ms=0) |
Returns True or False depending on whether all the data has been written to the socket. More... | |
int | listen (int backlog=20) |
Listens for connections on a bound socket; sets the socket in a listening state. More... | |
bool | pendingHttpChunkedBody () |
returns True if the socket is still connected, and a HTTP header was read indicating chunked transfer encoding, but no chunked body has been read yet More... | |
hash | readHTTPChunkedBody (timeout timeout_ms=-1) |
Reads in an HTTP message body sent in chunked transfer encoding and returns it with any footers received as a string in the "body" key of a hash (including footers received) More... | |
hash | readHTTPChunkedBodyBinary (timeout timeout_ms=-1) |
Reads in an HTTP message body sent in chunked transfer encoding and returns it with any footers received as a binary object in the "body" key of a hash (including footers received) More... | |
readHTTPChunkedBodyBinaryWithCallback (code rcb, timeout timeout_ms=-1) | |
Reads in an HTTP message body sent in chunked transfer encoding and returns it with any footers received as a string in the "body" key of a hash (including footers received) More... | |
readHTTPChunkedBodyWithCallback (code rcb, timeout timeout_ms=-1) | |
Reads in an HTTP message body sent in chunked transfer encoding and returns it with any footers received as a string in the "body" key of a hash (including footers received) More... | |
hash | readHTTPHeader (timeout timeout_ms=-1, *reference info) |
Retuns a hash representing the data in the HTTP header read, or, if the data cannot be parsed as an HTTP header, then an exception is thrown, and the data read is returned as a string in the arg key of the exception hash. More... | |
string | readHTTPHeaderString (timeout timeout_ms=-1) |
Retuns a string representing the data in the HTTP header read (reads until "\r\n\r\n" ) More... | |
string | recv (softint size=0, timeout timeout_ms=-1) |
Receives data from the socket and returns a string tagged with the Socket's character encoding. More... | |
binary | recvBinary (softint size=0, timeout timeout_ms=-1) |
Receives data from the socket and returns a binary object. More... | |
int | recvi1 (timeout timeout_ms=-1) |
Receives a 1-byte signed integer from the socket. More... | |
int | recvi2 (timeout timeout_ms=-1) |
Receives a 2-byte (16-bit) signed integer in big-endian format (network byte order) from the socket. More... | |
int | recvi2LSB (timeout timeout_ms=-1) |
Receives a 2-byte (16-bit) signed integer in little-endian format from the socket. More... | |
int | recvi4 (timeout timeout_ms=-1) |
Receives a 4-byte (32-bit) signed integer in big-endian format (network byte order) from the socket. More... | |
int | recvi4LSB (timeout timeout_ms=-1) |
Receives a 4-byte (32-bit) signed integer in little-endian format from the socket. More... | |
int | recvi8 (timeout timeout_ms=-1) |
Receives an 8-byte (64-bit) signed integer in big-endian format (network byte order) from the socket. More... | |
int | recvi8LSB (timeout timeout_ms=-1) |
Receives an 8-byte (64-bit) signed integer in little-endian format from the socket. More... | |
int | recvu1 (timeout timeout_ms=-1) |
Receives a 1-byte unsigned integer from the socket. More... | |
int | recvu2 (timeout timeout_ms=-1) |
Receives a 2-byte (16-bit) unsigned integer in big-endian format (network byte order) from the socket. More... | |
int | recvu2LSB (timeout timeout_ms=-1) |
Receives a 2-byte (16-bit) unsigned integer in little-endian format from the socket. More... | |
int | recvu4 (timeout timeout_ms=-1) |
Receives a 4-byte (32-bit) unsigned integer in big-endian format (network byte order) from the socket. More... | |
int | recvu4LSB (timeout timeout_ms=-1) |
Receives a 4-byte (32-bit) unsigned integer in little-endian format from the socket. More... | |
int | send (binary bin, int timeout_ms=-1) |
Sends binary data over the socket; if any errors occur, an exception is thrown. More... | |
int | send (string str, timeout timeout_ms=-1) |
Sends string data over the socket; string data is converted to the socket's encoding if necessary; if any errors occur, an exception is thrown. More... | |
nothing | send2 (binary bin, timeout timeout_ms=-1) |
Sends binary data over the socket; if any errors occur, an exception is thrown. More... | |
nothing | send2 (string str, timeout timeout_ms=-1) |
Sends string data over the socket; string data is converted to the socket's encoding if necessary; if any errors occur, an exception is thrown. More... | |
int | sendBinary (string str, timeout timeout_ms=-1) |
Sends string data over the socket without converting the string to the socket's encoding, but instead is sent exactly as-is; if any errors occur, an exception is thrown. More... | |
int | sendBinary (binary bin, timeout timeout_ms=-1) |
Sends binary data over the socket; if any errors occur, an exception is thrown. More... | |
nothing | sendBinary2 (string str, timeout timeout_ms=-1) |
Sends string data over the socket without converting the string to the socket's encoding, but instead is sent exactly as-is; if any errors occur, an exception is thrown. More... | |
nothing | sendBinary2 (binary bin, timeout timeout_ms=-1) |
Sends binary data over the socket; if any errors occur, an exception is thrown. More... | |
nothing | sendHTTPMessage (string method, string path, string http_version, hash headers, *string body, *reference info, timeout timeout_ms=-1) |
Sends an HTTP message with a method and user-defined headers given as a hash and an optional message body. More... | |
nothing | sendHTTPMessage (string method, string path, string http_version, hash headers, binary body, *reference info, timeout timeout_ms=-1) |
Sends an HTTP message with a method and user-defined headers given as a hash and an optional message body. More... | |
nothing | sendHTTPMessageWithCallback (code scb, string method, string path, string http_version, hash headers, *reference info, timeout timeout_ms=-1) |
Sends an HTTP message with a method and user-defined headers given as a hash and an optional message body. More... | |
nothing | sendHTTPResponse (softint status_code, string status_desc, string http_version, hash headers, *string body, timeout timeout_ms=-1) |
Sends an HTTP response with user-defined headers given as a hash and an optional message body. More... | |
nothing | sendHTTPResponse (softint status_code, string status_desc, string http_version, hash headers, binary body, timeout timeout_ms=-1) |
Sends an HTTP response with user-defined headers given as a hash and a message body as literal binary data. More... | |
nothing | sendHTTPResponseWithCallback (code scb, softint status_code, string status_desc, string http_version, hash headers, timeout timeout_ms=-1) |
Sends an HTTP response with user-defined headers given as a hash and a message body as literal binary data. More... | |
int | sendi1 (softint i=0, timeout timeout_ms=-1) |
Sends a 1-byte integer over the socket. More... | |
int | sendi2 (softint i=0, timeout timeout_ms=-1) |
Sends a 2-byte (16-bit) integer in big-endian format (network byte order) over the socket. More... | |
int | sendi2LSB (softint i=0, timeout timeout_ms=-1) |
Sends a 2-byte (16-bit) integer in little-endian format over the socket. More... | |
int | sendi4 (softint i=0, timeout timeout_ms=-1) |
Sends a 4-byte (32-bit) integer in big-endian format (network byte order) over the socket. More... | |
int | sendi4LSB (softint i=0, timeout timeout_ms=-1) |
Sends a 4-byte (32-bit) integer in little-endian format over the socket. More... | |
int | sendi8 (softint i=0, timeout timeout_ms=-1) |
Sends an 8-byte (64-bit) integer in big-endian format (network byte order) over the socket. More... | |
int | sendi8LSB (softint i=0, timeout timeout_ms=-1) |
Sends an 8-byte (64-bit) integer in little-endian format over the socket. More... | |
nothing | setCertificate (SSLCertificate cert) |
Sets the X.509 certificate to use for negotiating encrypted connections. More... | |
nothing | setCertificate (string cert_pem) |
Sets the X.509 certificate to use for negotiating encrypted connections from the PEM-encoded string representing the X.509 certificate. More... | |
nothing | setCertificate (binary cert_der) |
Sets the X.509 certificate to use for negotiating encrypted connections from the DER-encoded binary object representing the X.509 certificate. More... | |
nothing | setCharset (string encoding) |
Sets the character encoding for the socket. More... | |
nothing | setEncoding (string encoding) |
Sets the character encoding for the socket. More... | |
nothing | setEventQueue () |
Removes any Queue object from the Socket object so that socket events are no longer added to the Queue. More... | |
nothing | setEventQueue (Queue queue) |
Sets a Queue object to receive socket events. More... | |
int | setNoDelay (bool nd=True) |
Sets the boolean TCP_NODELAY setting for the socket. More... | |
nothing | setPrivateKey (SSLPrivateKey key) |
Sets the private key to use for negotiating encrypted connections along with the X.509 certificate. More... | |
nothing | setPrivateKey (string key_pem, *string pass) |
Sets the private key to use for negotiating encrypted connections along with the X.509 certificate from a PEM-encoded string representing the private key and an optional password. More... | |
nothing | setPrivateKey (binary key_der) |
Sets the private key to use for negotiating encrypted connections along with the X.509 certificate from a DER-encoded binary object representing the private key. More... | |
int | setRecvTimeout (timeout timeout_ms) |
sets the receive timeout as a socket option More... | |
int | setSendTimeout (timeout timeout_ms) |
sets the send timeout as a socket option More... | |
nothing | setWarningQueue (int warning_ms, int warning_bs, Queue queue, any arg, timeout min_ms=1s) |
Sets a Queue object to receive socket warnings. More... | |
int | shutdown () |
Ensures that a socket will be closed even if the file descriptor is shared with other processes (for example, after a call to fork()) More... | |
nothing | shutdownSSL () |
Shuts down the SSL connection on a secure connection. More... | |
nothing | upgradeClientToSSL () |
Upgrades a client socket connection to a TLS/SSL connection. More... | |
nothing | upgradeServerToSSL () |
Upgrades a server socket connection to a TLS/SSL connection. More... | |
*string | verifyPeerCertificate () |
Returns a string code giving the result of verifying the remote certificate or NOTHING if an encrypted connection is not currently established. More... | |
The Socket class allows Qore programs safe access to network sockets.
Non-blocking socket I/O can be performed by appending a timeout value in milliseconds all Socket methods performing I/O operations, or by using the Socket::isDataAvailable() method with a timeout value in milliseconds (1000 ms = 1 second). Note that as with all Qore functions and methods accepting a timeout value, relative date/time values can be given instead of integers to make the source more readable, for example:
Socket objects can automatically convert character encodings if desired when sending string data with Socket::send(). Use the Socket::setEncoding() method to set the character encoding for the socket. If a character encoding is set, and string data is read with the Socket::recv() method, then it will be tagged with the encoding of the socket as well.
Client applications should call Socket::connect() to connect to a remote port or a UNIX domain socket (socket file on the local server). However, if the remote end is expecting a TLS/SSL connection, use Socket::connectSSL() instead.
Server applications should call Socket::bind(), Socket::listen(), and Socket::accept() in this order to accept incoming connections. Normally a new thread should be started after the Socket::accept() call to handle the new connection in a separate thread (Socket::accept() returns a new Socket object for the accepted connection).
To support TLS/SSL server connections, first set the certificate and private key with the Socket::setCertificate() and Socket::setPrivateKey() methods (see the SSLCertificate Class and the SSLPrivateKey Class for more information on the parameters required for these methods). Then Socket::acceptSSL() should be called after the socket is in a listening state to accept client connections and negotiate a TLS/SSL connection.
This class supports posting events to a Queue. See I/O Event Handling for more information.
The events raised by this object are listed in the following table:
Socket Events
Name | Description |
EVENT_PACKET_READ | Raised when a network packet is received. |
EVENT_PACKET_SENT | Raised when a network packet is sent. |
EVENT_CHANNEL_CLOSED | Raised when a socket is closed. |
EVENT_DELETED | Raised when the object being monitored is deleted. |
EVENT_HOSTNAME_LOOKUP | Raised when a hostname lookup is attempted. |
EVENT_HOSTNAME_RESOLVED | Raised when a hostname lookup is resolved. |
EVENT_HTTP_SEND_MESSAGE | Raised when an HTTP message is sent. |
EVENT_HTTP_MESSAGE_RECEIVED | Raised when an HTTP message is received. |
EVENT_CONNECTING | Raised right before a socket connection attempt is made. |
EVENT_CONNECTED | Raised when the socket connection has been established. |
EVENT_START_SSL | Raised when socket SSL negotiation starts. |
EVENT_SSL_ESTABLISHED | Raised when SSL communication has been negotiated and established. |
Socket Information Hash
Key | Description |
hostname | The interface name if available (ex: "localhost" ; note that this key is not present when retrieving information about UNIX sockets) |
hostname_desc | A descriptive string giving the hostname and the address family if the hostname is available (ex: "ipv6[localhost]" ; note that this key is not present when retrieving information about UNIX sockets) |
address | A string giving the address (ex: "::ffff:0.0.0.0" ) |
address_desc | A descriptive string giving the address and the address family (ex: "ipv6[::ffff:0.0.0.0]" ) |
port | An integer port number if available (note that this key is not present when retrieving information about UNIX sockets) |
family | The network address family (see Network Address Family Constants) |
familystr | A string describing the network address family (ex: "ipv4" ) |
Socket Qore::Socket::accept | ( | ) |
Accepts connections on a listening socket.
Accepts connections on a listening socket; if any errors occur, an exception is thrown.
The new Socket object returned will have the same character encoding as the current object. Once a new connection has been accepted, call Socket::getPeerInfo() to get information about the remote socket.
SOCKET-NOT-OPEN | The socket is not bound |
SOCKET-ACCEPT-ERROR | Error in accepting connection |
*Socket Qore::Socket::accept | ( | timeout | timeout_ms | ) |
Accepts connections on a listening socket (see Socket::listen()) accepting a timeout value with a millisecond resolution.
If any errors occur, an exception is thrown.
The new Socket object returned will have the same character encoding as the current object. Once a new connection has been accepted, call Socket::getPeerInfo() to get information about the remote socket.
timeout_ms | If a timeout value is passed and the connection takes longer to establish than the timeout, then NOTHING is returned.Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not bound |
SOCKET-ACCEPT-ERROR | Error in accepting connection |
Socket Qore::Socket::acceptSSL | ( | ) |
Accepts connections on a listening socket and attempts to negotiate a TLS/SSL connection.
Accepts connections on a listening socket and attempts to negotiate a TLS/SSL connection; if any errors occur, an exception is thrown.
The new Socket object returned will have the same character encoding as the current object. Once a new connection has been accepted, call Socket::getPeerInfo() to get information about the remote socket.
SOCKET-NOT-OPEN | The socket is not bound |
SOCKET-ACCEPT-ERROR | Error in accepting connection |
*Socket Qore::Socket::acceptSSL | ( | timeout | timeout_ms | ) |
Accepts connections on a listening socket and attempts to negotiate a TLS/SSL connection accepting a timeout value with a millisecond resolution.
If any errors occur, an exception is thrown.
The new Socket object returned will have the same character encoding as the current object. Once a new connection has been accepted, call Socket::getPeerInfo() to get information about the remote socket.
timeout_ms | If a timeout value is passed and the connection takes longer to establish than the timeout, then NOTHING is returned. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not bound |
SOCKET-ACCEPT-ERROR | Error in accepting connection |
Opens and binds the socket to a port, interface and port (if the $bind_to string has a format "host:port"), or UNIX domain socket file.
If the second parameter is True, then the socket will set the SO_REUSEADDR
option, which will allow the socket to be bound to a port that is not yet closed (for example, in a TIME_WAIT
state).
If any errors occur a non-zero error code is returned.
This method tries to automatically pick the appropriate address family from the arguments; note that a hostname or address in square brackets (ex: "[localhost]"
) will be looked up and bound as an IPv6 address; additionally, the method recognizes ipv6 addresses by embedded colons (:) in the address string and binds them as such.
Internally, the getaddrinfo() function is used to look up bind addresses; internal bind()
operations are tried in sequence for each address returned; as soon as a bind operation is successful, the method returns. If none of the addresses can be bound, then an error code is returned.
str | If a colon appears in the string, the string will be assumed to be a "bind_address:port" specification, and the port on the named IP address will be bound, otherwise, if the string contains no colon, the socket will be bound to a UNIX domain socket file on the local filesystem with the given name. Note that a hostname or address in square brackets (ex: "[localhost]" ) will be looked up and bound as an IPv6 address; additionally, the method recognizes ipv6 addresses by embedded colons (:) in the address string (if surrounded by square brackets) and binds them as such. |
reuseaddr | If this optional argument evaluates to True, the SO_REUSEADDR option will be set on the socket, which will allow the socket to be bound to a port that is not yet closed (for example, in a TIME_WAIT state); note that this only applies to IPv4 (AF_INET) and IPv6 (AF_INET6) sockets; this option is ignored for UNIX (AF_UNIX) sockets. |
Opens and binds the socket to an INET port on all interfaces.
If the second parameter is True, then the socket will set the SO_REUSEADDR
option, which will allow the socket to be bound to a port that is not yet closed (for example, in a TIME_WAIT
state).
If any errors occur a non-zero error code is returned.
port | A port number to bind to on all interfaces |
reuseaddr | If this optional argument evaluates to True, the SO_REUSEADDR option will be set on the socket, which will allow the socket to be bound to a port that is not yet closed (for example, in a TIME_WAIT state) |
nothing Qore::Socket::bindINET | ( | *string | iface, |
*softstring | service, | ||
softbool | reuseaddr = False , |
||
softint | family = AF_UNSPEC , |
||
softint | socktype = SOCK_STREAM , |
||
softint | protocol = 0 |
||
) |
Opens and binds the socket to the given IPv4 or IPv6 interface (or if no interface is given, then to all interfaces on the local system) and port (the port number will be derived from the service name if a numeric port number is not given)
Opens and binds the socket to a port, interface and port (if the interface string has a format "host:port"
), or UNIX domain socket file (if no port or service name appears in the bind string). If the second parameter is True, then the socket will set the SO_REUSEADDR
option, which will allow the socket to be bound to a port that is not yet closed (for example, in a TIME_WAIT
state).
Internally, the getaddrinfo() function is used to look up bind addresses; internal bind() operations are tried in sequence for each address returned; as soon as a bind operation is successful, the method returns. If none of the addresses can be bound, then an error code is returned.
If any errors occur, an exception is thrown.
iface | the host name or IP address to bind to |
service | the service name (ex: "http" or port number (given as or converted to a string) to bind to |
reuseaddr | if this optional argument evaluates to True, the SO_REUSEADDR option will be set on the socket, which will allow the socket to be bound to a port that is not yet closed (for example, in a TIME_WAIT state) |
family | the address family to use to bind; see Network Address Family Constants; AF_UNSPEC means to try all possible addres families |
socktype | the type of socket; see Socket Type Constants; typically SOCK_STREAM for TCP sockets |
protocol | the protocol number for the socket; use 0 for the default protocol |
SOCKET-BIND-ERROR | Both hostname and service name are empty or not set; error opening socket for bind; error binding on socket. |
QOREADDRINFO-GETINFO-ERROR | error looking up either nodename or servicename (or not known) |
nothing Qore::Socket::bindUNIX | ( | string | path, |
softint | socktype = SOCK_STREAM , |
||
softint | protocol = 0 |
||
) |
Opens and binds the socket to the given UNIX domain socket file as given by the filename argument. If any errors occur, an exception is thrown.
Opens and binds the socket to the given UNIX domain socket file as given by the filename argument. Note that the socket file is automatically deleted in the destructor when a UNIX socket is closed. If any errors occur, an exception is thrown.
path | The path of the UNIX domain socket to create and bind to |
socktype | the type of socket; see Socket Type Constants; typically SOCK_STREAM for TCP sockets |
protocol | the protocol number for the socket; use 0 for the default protocol |
SOCKET-BIND-ERROR | Error opening socket for bind; error binding on socket |
Qore::Socket::clearStats | ( | ) |
Clears performance statistics.
nothing Qore::Socket::clearWarningQueue | ( | ) |
Removes any warning Queue object from the Socket.
int Qore::Socket::close | ( | ) |
Closes an open socket.
Also deletes the UNIX domain socket file if it was created by a call to Socket::bind(). Returns 0 for success, -1 for error; in this case check errno() for the error number
nothing Qore::Socket::connect | ( | string | target, |
timeout | timeout_ms = -1 |
||
) |
Connects to a remote port (if the string has a format "host:port") or UNIX domain socket file with an optional timeout value with a millisecond resolution.
Connects the socket to a remote (or local) port or UNIX domain socket file, for network (ipv4 and ipv6) connections, accepts an optional timeout value in milliseconds (relative date/time values can be given instead of an integer in milliseconds to make the source more readable; ex: 20s
). If any errors occur, an exception is thrown.
target | The target address interpreted with the following rules:
|
timeout_ms | If a timeout value is passed and the connection takes longer to establish than the timeout, a "SOCKET-CONNECT-ERROR" exception is thrown. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-CONNECT-ERROR | An error occured connecting to the remote socket (cannot resolve hostname, no listener, timeout exceeded, etc). |
nothing Qore::Socket::connectINET | ( | string | host, |
softstring | service, | ||
timeout | timeout_ms = -1 , |
||
softint | family = AF_UNSPEC , |
||
softint | socktype = SOCK_STREAM , |
||
softint | protocol = 0 |
||
) |
Connects to the given host and port with an optional timeout value with a millisecond resolution.
Connects the socket to a remote (or local) port; accepts an optional timeout value in milliseconds (relative date/time values can be given instead of an integer in milliseconds to make the source more readable; ex: 20s
). If any errors occur, an exception is thrown.
Do not use square brackets to designate ipv6 addresses with this method; just give the address in its normal form (ex: "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
).
host | The host name or IP address to connect to |
service | The service name (ex: "http" or port number (given as or converted to a string) to connect to |
timeout_ms | If a timeout value is passed and the connection takes longer to establish than the timeout, a "SOCKET-CONNECT-ERROR" exception is thrown. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
family | The address family to use to connect to the remote socket; see Network Address Family Constants |
socktype | The type of socket; see Socket Type Constants; typically SOCK_STREAM for TCP sockets |
protocol | The protocol number for the socket (if not sure leave this 0) |
SOCKET-CONNECT-ERROR | An error occured connecting to the remote socket (cannot resolve hostname, no listener, timeout exceeded, etc) |
nothing Qore::Socket::connectINETSSL | ( | string | host, |
softstring | service, | ||
timeout | timeout_ms = -1 , |
||
softint | family = AF_UNSPEC , |
||
softint | socktype = SOCK_STREAM , |
||
softint | protocol = 0 |
||
) |
Connects to the given host and port and attempts to establish a TLS/SSL connection; accepts an optional timeout value with a millisecond resolution.
Connects the socket to a remote (or local) port and attempts to establish a TLS/SSL connection; accepts an optional timeout value in milliseconds (relative date/time values can be given instead of an integer in milliseconds to make the source more readable; ex: 20s
). If any errors occur, an exception is thrown.
Do not use square brackets to designate ipv6 addresses with this method; just give the address in its normal form (ex: "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
).
host | The host name or IP address to connect to |
service | The service name (ex: "http" or port number (given as or converted to a string) to connect to |
timeout_ms | If a timeout value is passed and the connection takes longer to establish than the timeout, a "SOCKET-CONNECT-ERROR" exception is thrown. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
family | The address family to use to connect to the remote socket; see Network Address Family Constants |
socktype | The type of socket; see Socket Type Constants; typically SOCK_STREAM for TCP sockets |
protocol | The protocol number for the socket (if not sure leave this 0) |
SOCKET-CONNECT-ERROR | An error occured connecting to the remote socket (cannot resolve hostname, no listener, timeout exceeded, etc) |
SOCKET-SSL-ERROR | An error occurred establishing the TLS/SSL connection |
nothing Qore::Socket::connectSSL | ( | string | target, |
timeout | timeout_ms = -1 |
||
) |
Connects to a remote socket and attempts to establish a TLS/SSL connection; accepts an optional timeout value with a millisecond resolution.
Connects to a remote socket and attempts to establish a TLS/SSL connection, for network (INET) connections, accepts an optional timeout value in milliseconds (relative date/time values can be given instead of an integer in milliseconds to make the source more readable; ex: 20s
). If any errors occur, an exception is thrown.
Enclose ipv6 addresses in square brackets (ex: "[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80"
, will connect to port 80 on the given ipv6 address); also if a hostname is enclosed in square brackets, it will be resolved as an ipv6 adress (ex: "[localhost]:80"
will connect to port 80
on ::1, assuming
"localhost"
can be resolved to the ipv6 loopback address on the system).
target | The target address interpreted with the following rules:
|
timeout_ms | if a timeout value is passed and the connection takes longer to establish than the timeout, an exception is thrown. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-CONNECT-ERROR | An error occured connecting to the remote socket (cannot resolve hostname, no listener, timeout exceeded, etc) |
SOCKET-SSL-ERROR | An error occurred establishing the TLS/SSL connection |
nothing Qore::Socket::connectUNIX | ( | string | path, |
softint | socktype = SOCK_STREAM , |
||
softint | protocol = 0 |
||
) |
Connects to a UNIX domain socket file.
Connects the socket to the given UNIX domain socket file; if any errors occur, an exception is thrown
path | The socket will try to connect to a UNIX domain socket file on the local filesystem with the given name |
socktype | The type of socket; see Socket Type Constants; typically SOCK_STREAM for TCP sockets |
protocol | The protocol number for the socket (if not sure leave this 0) |
SOCKET-CONNECT-ERROR | An error occured connecting to the socket |
nothing Qore::Socket::connectUNIXSSL | ( | string | path, |
softint | socktype = SOCK_STREAM , |
||
softint | protocol = 0 |
||
) |
Connects to the given UNIX domain socket file and attempts to establish a TLS/SSL connection.
Connects the socket to a UNIX domain socket file and attempts to establish a TLS/SSL connection. If any errors occur, an exception is thrown.
path | The socket will try to connect to a UNIX domain socket file on the local filesystem with the given name |
socktype | The type of socket; see Socket Type Constants; typically SOCK_STREAM for TCP sockets |
protocol | The protocol number for the socket (if not sure leave this 0) |
SOCKET-CONNECT-ERROR | An error occured connecting to the socket |
SOCKET-SSL-ERROR | An error occurred establishing the TLS/SSL connection |
Qore::Socket::constructor | ( | ) |
Creates the socket object.
Qore::Socket::copy | ( | ) |
Creates a new Socket object, not based on the source being copied.
string Qore::Socket::getCharset | ( | ) |
Returns the character encoding for the socket.
A method synonym for Socket::getEncoding(), kept for backwards-compatibility
string Qore::Socket::getEncoding | ( | ) |
Returns the character encoding for the socket.
bool Qore::Socket::getNoDelay | ( | ) |
Returns the TCP_NODELAY
setting for the socket.
TCP_NODELAY
setting for the socketTCP_NODELAY
setting Returns a hash of information about the remote end for connected sockets.
If the socket is not connected, an exception is thrown
host_lookup | do a lookup of the hostname; if this is False then "hostname" and "hostname_desc" are not present in the response hash |
SOCKET-GETPEERINFO-ERROR | Socket is not open or error in getpeername() |
int Qore::Socket::getPort | ( | ) |
Returns the port number of the socket for INET sockets.
int Qore::Socket::getRecvTimeout | ( | ) |
Returns the receive timeout socket option value as an integer in milliseconds.
int Qore::Socket::getSendTimeout | ( | ) |
Returns the send timeout socket option value as an integer in milliseconds.
int Qore::Socket::getSocket | ( | ) |
Returns the socket file descriptor number.
Returns information about the local socket as a hash.
If the socket is not open, an exception is thrown
host_lookup | do a lookup of the hostname; if this is False then "hostname" and "hostname_desc" are not present in the response hash |
SOCKET-GETSOCKETINFO-ERROR | Socket is not open or error in getsockname() |
*string Qore::Socket::getSSLCipherName | ( | ) |
Returns the name of the cipher for an encrypted connection or NOTHING if a secure connection has not been established.
*string Qore::Socket::getSSLCipherVersion | ( | ) |
Returns the version string of the cipher for an encrypted connection or NOTHING if a secure connection has not been established.
hash Qore::Socket::getUsageInfo | ( | ) |
Returns performance statistics for the socket.
"bytes_sent"
: an integer giving the total amount of bytes sent"bytes_recv"
: an integer giving the total amount of bytes received"us_sent"
: an integer giving the total number of microseconds spent sending data"us_recv"
: an integer giving the total number of microseconds spent receiving data"arg"
: (only if warning values have been set with Socket::setWarningQueue()) the optional argument for warning hashes"timeout"
: (only if warning values have been set with Socket::setWarningQueue()) the warning timeout in microseconds"min_throughput"
: (only if warning values have been set with Socket::setWarningQueue()) the minimum warning throughput in bytes/secbool Qore::Socket::isDataAvailable | ( | timeout | timeout_ms = 0 | ) |
Returns True or False depending on whether there is data to be read on the socket.
With a timeout of zero this method returns immediately and can be used for non-blocking polling the socket for data (can also be used to poll for new connections before Socket::accept()).
timeout_ms | an optional timeout in milliseconds (1/1000 second); if no timeout is given, the method returns immediately; Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-CLOSED | The remote end closed the connection without sending any data |
bool Qore::Socket::isOpen | ( | ) |
bool Qore::Socket::isSecure | ( | ) |
bool Qore::Socket::isWriteFinished | ( | timeout | timeout_ms = 0 | ) |
Returns True or False depending on whether all the data has been written to the socket.
With a timeout of zero this method returns immediately.
timeout_ms | an optional timeout in milliseconds (1/1000 second); if no timeout is given, the method returns immediately; Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-CLOSED | The remote end closed the connection without sending any data |
Listens for connections on a bound socket; sets the socket in a listening state.
Listens for new connections on a bound socket.
backlog | the size of the queue for pending connections |
SOCKET-NOT-OPEN | The socket is not bound |
bool Qore::Socket::pendingHttpChunkedBody | ( | ) |
returns True if the socket is still connected, and a HTTP header was read indicating chunked transfer encoding, but no chunked body has been read yet
hash Qore::Socket::readHTTPChunkedBody | ( | timeout | timeout_ms = -1 | ) |
Reads in an HTTP message body sent in chunked transfer encoding and returns it with any footers received as a string in the "body"
key of a hash (including footers received)
If any errors are encountered, an exception is raised
timeout_ms | The timeout in milliseconds (1/1000 second). If no timeout or if a negative timeout is passed, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. If a timeout occurs, a "SOCKET-TIMEOUT" exception is raised. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
"body"
key as a string in the Socket's encodingSOCKET-NOT-OPEN | The socket is not connected |
SOCKET-CLOSED | The remote end has closed the connection |
SOCKET-RECV-ERROR | There was an error receiving the data |
SOCKET-TIMEOUT | The data requested was not received in the timeout period |
SOCKET-SSL-ERROR | There was an SSL error while reading data from the socket |
READ-HTTP-CHUNK-ERROR | negative value given for chunk size by server |
hash Qore::Socket::readHTTPChunkedBodyBinary | ( | timeout | timeout_ms = -1 | ) |
Reads in an HTTP message body sent in chunked transfer encoding and returns it with any footers received as a binary object in the "body"
key of a hash (including footers received)
If any errors are encountered, an exception is raised
timeout_ms | The timeout in milliseconds (1/1000 second). If no timeout or if a negative timeout is passed, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. If a timeout occurs, a "SOCKET-TIMEOUT" exception is raised. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
"body"
key as a binary objectSOCKET-NOT-OPEN | The socket is not connected |
SOCKET-CLOSED | The remote end has closed the connection |
SOCKET-RECV-ERROR | There was an error receiving the data |
SOCKET-TIMEOUT | The data requested was not received in the timeout period |
SOCKET-SSL-ERROR | There was an SSL error while reading data from the socket |
READ-HTTP-CHUNK-ERROR | negative value given for chunk size by server |
Qore::Socket::readHTTPChunkedBodyBinaryWithCallback | ( | code | rcb, |
timeout | timeout_ms = -1 |
||
) |
Reads in an HTTP message body sent in chunked transfer encoding and returns it with any footers received as a string in the "body"
key of a hash (including footers received)
If any errors are encountered, an exception is raised
rcb | The receive callback for the data received; first this method is called with a hash of the message headers, and then with any message body; if a chunked HTTP message is received, then the callback is called once for each chunk; when the message has been received, then the receive callback is called with a hash representing any trailer data received in a chunked transfer or NOTHING if the data was received in a normal message body or if there was no trailer data in a chunked transfer. The argument to this callback is always a hash; data calls have the following keys:
|
timeout_ms | The timeout in milliseconds (1/1000 second). If no timeout or if a negative timeout is passed, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. If a timeout occurs, a "SOCKET-TIMEOUT" exception is raised. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-CLOSED | The remote end has closed the connection |
SOCKET-RECV-ERROR | There was an error receiving the data |
SOCKET-TIMEOUT | The data requested was not received in the timeout period |
SOCKET-SSL-ERROR | There was an SSL error while reading data from the socket |
READ-HTTP-CHUNK-ERROR | negative value given for chunk size by server |
Qore::Socket::readHTTPChunkedBodyWithCallback | ( | code | rcb, |
timeout | timeout_ms = -1 |
||
) |
Reads in an HTTP message body sent in chunked transfer encoding and returns it with any footers received as a string in the "body"
key of a hash (including footers received)
If any errors are encountered, an exception is raised
rcb | The receive callback for the data received; first this method is called with a hash of the message headers, and then with any message body; if a chunked HTTP message is received, then the callback is called once for each chunk; when the message has been received, then the receive callback is called with a hash representing any trailer data received in a chunked transfer or NOTHING if the data was received in a normal message body or if there was no trailer data in a chunked transfer. The argument to this callback is always a hash; data calls have the following keys:
|
timeout_ms | The timeout in milliseconds (1/1000 second). If no timeout or if a negative timeout is passed, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. If a timeout occurs, a "SOCKET-TIMEOUT" exception is raised. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-CLOSED | The remote end has closed the connection |
SOCKET-RECV-ERROR | There was an error receiving the data |
SOCKET-TIMEOUT | The data requested was not received in the timeout period |
SOCKET-SSL-ERROR | There was an SSL error while reading data from the socket |
READ-HTTP-CHUNK-ERROR | negative value given for chunk size by server |
hash Qore::Socket::readHTTPHeader | ( | timeout | timeout_ms = -1 , |
*reference | info | ||
) |
Retuns a hash representing the data in the HTTP header read, or, if the data cannot be parsed as an HTTP header, then an exception is thrown, and the data read is returned as a string in the arg
key of the exception hash.
If any errors occur reading from the socket or if invalid HTTP data is received, an exception is raised. Accepts an optional timeout value in milliseconds.
timeout_ms | The timeout in milliseconds (1/1000 second). If no timeout or if a negative timeout is passed, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. If a timeout occurs, a "SOCKET-TIMEOUT" exception is raised. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
info | An optional reference to an lvalue that can accept a hash that will be used as an output variable with one of the following two keys:
|
http_version:
a string giving the HTTP version set in the headerstatus_code:
(HTTP responses only) an integer giving the status codestatus_message:
(HTTP responses only) if present in an HTTP response, this key will be set to the message after the status codemethod:
(HTTP requests only) a string giving the HTTP method (i.e. "GET"
, "POST"
, etc)path:
(HTTP requests only) a string giving the path in a request without any decoding; use decode_url() to decode if necessarySOCKET-NOT-OPEN | The socket is not connected |
SOCKET-CLOSED | The remote end closed the connection without sending any data |
SOCKET-RECV-ERROR | There was an error receiving the data |
SOCKET-TIMEOUT | The data requested was not received in the timeout period |
SOCKET-SSL-ERROR | There was an SSL error while reading data from the socket |
SOCKET-HTTP-ERROR | Invalid HTTP data was received, in the case of invalid header info received, the arg key of the exception hash will have the invalid data received |
charset
declaration in the "Content-Type"
header, the Socket's character encoding is automatically set accordingly"iso-8859-1"
SOCKET-HTTP-ERROR
if invalid HTTP data is receivedclose
, charset
, body-content-type
, and accept-charset
info keys as well as the encoding handling based on the detected charset string Qore::Socket::readHTTPHeaderString | ( | timeout | timeout_ms = -1 | ) |
Retuns a string representing the data in the HTTP header read (reads until "\r\n\r\n"
)
If any errors occur reading from the socket, an exception is raised. Accepts an optional timeout value in milliseconds.
timeout_ms | The timeout in milliseconds (1/1000 second). If no timeout or if a negative timeout is passed, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. If a timeout occurs, a "SOCKET-TIMEOUT" exception is raised. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-CLOSED | The remote end closed the connection without sending any data |
SOCKET-RECV-ERROR | There was an error receiving the data |
SOCKET-TIMEOUT | The data requested was not received in the timeout period |
SOCKET-SSL-ERROR | There was an SSL error while reading data from the socket |
SOCKET-HTTP-ERROR | maximum header size was exceeded |
string Qore::Socket::recv | ( | softint | size = 0 , |
timeout | timeout_ms = -1 |
||
) |
Receives data from the socket and returns a string tagged with the Socket's character encoding.
If any errors occur reading from the socket, an exception is raised
size | the amount of data to read in bytes; to read until the remote closes the connection, use -1; a value of 0 means to read all data currently available or available up until the timeout period (if non-negative) |
timeout_ms | the timeout in milliseconds (1/1000 second). If no timeout is passed, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-CLOSED | the remote end has closed the connection. |
SOCKET-RECV-ERROR | there was an error receiving the data. |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SSL-ERROR | there was an SSL error while reading data from the socket |
binary Qore::Socket::recvBinary | ( | softint | size = 0 , |
timeout | timeout_ms = -1 |
||
) |
Receives data from the socket and returns a binary object.
If any errors occur reading from the socket, an exception is raised
size | the amount of data to read in bytes; to read until the remote closes the connection, use -1; a value of 0 means to read all data currently available or available up until the timeout period (if non-negative) |
timeout_ms | the timeout in milliseconds (1/1000 second). If no timeout is passed, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-CLOSED | the remote end has closed the connection. |
SOCKET-RECV-ERROR | there was an error receiving the data. |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SSL-ERROR | there was an SSL error while reading data from the socket |
int Qore::Socket::recvi1 | ( | timeout | timeout_ms = -1 | ) |
Receives a 1-byte signed integer from the socket.
If any errors occur reading from the socket, an exception is raised
timeout_ms | the timeout in milliseconds (1/1000 second); If no timeout is passed or is negative, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-CLOSED | the remote end has closed the connection |
SOCKET-RECV-ERROR | there was an error receiving the data |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SSL-ERROR | there was an SSL error while reading data from the socket |
int Qore::Socket::recvi2 | ( | timeout | timeout_ms = -1 | ) |
Receives a 2-byte (16-bit) signed integer in big-endian format (network byte order) from the socket.
If any errors occur reading from the socket, an exception is raised
timeout_ms | the timeout in milliseconds (1/1000 second); If no timeout is passed or is negative, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-CLOSED | the remote end has closed the connection |
SOCKET-RECV-ERROR | there was an error receiving the data |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SSL-ERROR | there was an SSL error while reading data from the socket |
int Qore::Socket::recvi2LSB | ( | timeout | timeout_ms = -1 | ) |
Receives a 2-byte (16-bit) signed integer in little-endian format from the socket.
If any errors occur reading from the socket, an exception is raised
timeout_ms | the timeout in milliseconds (1/1000 second); If no timeout is passed or is negative, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-CLOSED | the remote end has closed the connection |
SOCKET-RECV-ERROR | there was an error receiving the data |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SSL-ERROR | there was an SSL error while reading data from the socket |
int Qore::Socket::recvi4 | ( | timeout | timeout_ms = -1 | ) |
Receives a 4-byte (32-bit) signed integer in big-endian format (network byte order) from the socket.
If any errors occur reading from the socket, an exception is raised
timeout_ms | the timeout in milliseconds (1/1000 second); If no timeout is passed or is negative, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-CLOSED | the remote end has closed the connection |
SOCKET-RECV-ERROR | there was an error receiving the data |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SSL-ERROR | there was an SSL error while reading data from the socket |
int Qore::Socket::recvi4LSB | ( | timeout | timeout_ms = -1 | ) |
Receives a 4-byte (32-bit) signed integer in little-endian format from the socket.
If any errors occur reading from the socket, an exception is raised
timeout_ms | the timeout in milliseconds (1/1000 second); If no timeout is passed or is negative, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-CLOSED | the remote end has closed the connection |
SOCKET-RECV-ERROR | there was an error receiving the data |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SSL-ERROR | there was an SSL error while reading data from the socket |
int Qore::Socket::recvi8 | ( | timeout | timeout_ms = -1 | ) |
Receives an 8-byte (64-bit) signed integer in big-endian format (network byte order) from the socket.
If any errors occur reading from the socket, an exception is raised
timeout_ms | the timeout in milliseconds (1/1000 second); If no timeout is passed or is negative, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-CLOSED | the remote end has closed the connection |
SOCKET-RECV-ERROR | there was an error receiving the data |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SSL-ERROR | there was an SSL error while reading data from the socket |
int Qore::Socket::recvi8LSB | ( | timeout | timeout_ms = -1 | ) |
Receives an 8-byte (64-bit) signed integer in little-endian format from the socket.
If any errors occur reading from the socket, an exception is raised
timeout_ms | the timeout in milliseconds (1/1000 second); If no timeout is passed or is negative, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-CLOSED | the remote end has closed the connection |
SOCKET-RECV-ERROR | there was an error receiving the data |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SSL-ERROR | there was an SSL error while reading data from the socket |
int Qore::Socket::recvu1 | ( | timeout | timeout_ms = -1 | ) |
Receives a 1-byte unsigned integer from the socket.
If any errors occur reading from the socket, an exception is raised
timeout_ms | the timeout in milliseconds (1/1000 second); If no timeout is passed or is negative, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-CLOSED | the remote end has closed the connection |
SOCKET-RECV-ERROR | there was an error receiving the data |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SSL-ERROR | there was an SSL error while reading data from the socket |
int Qore::Socket::recvu2 | ( | timeout | timeout_ms = -1 | ) |
Receives a 2-byte (16-bit) unsigned integer in big-endian format (network byte order) from the socket.
If any errors occur reading from the socket, an exception is raised
timeout_ms | the timeout in milliseconds (1/1000 second); If no timeout is passed or is negative, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-CLOSED | the remote end has closed the connection |
SOCKET-RECV-ERROR | there was an error receiving the data |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SSL-ERROR | there was an SSL error while reading data from the socket |
int Qore::Socket::recvu2LSB | ( | timeout | timeout_ms = -1 | ) |
Receives a 2-byte (16-bit) unsigned integer in little-endian format from the socket.
If any errors occur reading from the socket, an exception is raised
timeout_ms | the timeout in milliseconds (1/1000 second); If no timeout is passed or is negative, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-CLOSED | the remote end has closed the connection |
SOCKET-RECV-ERROR | there was an error receiving the data |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SSL-ERROR | there was an SSL error while reading data from the socket |
int Qore::Socket::recvu4 | ( | timeout | timeout_ms = -1 | ) |
Receives a 4-byte (32-bit) unsigned integer in big-endian format (network byte order) from the socket.
If any errors occur reading from the socket, an exception is raised
timeout_ms | the timeout in milliseconds (1/1000 second); If no timeout is passed or is negative, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-CLOSED | the remote end has closed the connection |
SOCKET-RECV-ERROR | there was an error receiving the data |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SSL-ERROR | there was an SSL error while reading data from the socket |
int Qore::Socket::recvu4LSB | ( | timeout | timeout_ms = -1 | ) |
Receives a 4-byte (32-bit) unsigned integer in little-endian format from the socket.
If any errors occur reading from the socket, an exception is raised
timeout_ms | the timeout in milliseconds (1/1000 second); If no timeout is passed or is negative, then the call will not time out and will not return until all the data has been read or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-CLOSED | the remote end has closed the connection |
SOCKET-RECV-ERROR | there was an error receiving the data |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SSL-ERROR | there was an SSL error while reading data from the socket |
Sends binary data over the socket; if any errors occur, an exception is thrown.
bin | Sends the binary data over the socket |
timeout_ms | the timeout in milliseconds (1/1000 second). If no timeout is passed, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection; the timeout value is the longest value that a single send() operation can take with non-blocking I/O. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-TIMEOUT | a single send() operation exceeded the given timeout period |
SOCKET-SEND-ERROR | an error occurred sending the socket data |
SOCKET-SSL-ERROR | there was an SSL error while writing data to the socket |
Sends string data over the socket; string data is converted to the socket's encoding if necessary; if any errors occur, an exception is thrown.
String data will be converted to the encoding set for the socket if necessary.
str | sends the string data over the socket without the trailing null ('\0') character; the string's encoding is converted to the socket's encoding if necessary |
timeout_ms | the timeout in milliseconds (1/1000 second). If no timeout is passed, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection; the timeout value is the longest value that a single send() operation can take with non-blocking I/O. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-TIMEOUT | a single send() operation exceeded the given timeout period |
SOCKET-SEND-ERROR | an error occurred sending the socket data |
SOCKET-SSL-ERROR | there was an SSL error while writing data to the socket |
nothing Qore::Socket::send2 | ( | binary | bin, |
timeout | timeout_ms = -1 |
||
) |
Sends binary data over the socket; if any errors occur, an exception is thrown.
bin | Sends the binary data over the socket |
timeout_ms | the timeout in milliseconds (1/1000 second). If no timeout is passed, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection; the timeout value is the longest value that a single send() operation can take with non-blocking I/O. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-TIMEOUT | a single send() operation exceeded the given timeout period |
SOCKET-SEND-ERROR | an error occurred sending the socket data |
SOCKET-SSL-ERROR | there was an SSL error while writing data to the socket |
nothing Qore::Socket::send2 | ( | string | str, |
timeout | timeout_ms = -1 |
||
) |
Sends string data over the socket; string data is converted to the socket's encoding if necessary; if any errors occur, an exception is thrown.
String data will be converted to the encoding set for the socket if necessary.
str | sends the string data over the socket without the trailing null ('\0') character; the string's encoding is converted to the socket's encoding if necessary |
timeout_ms | the timeout in milliseconds (1/1000 second). If no timeout is passed, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection; the timeout value is the longest value that a single send() operation can take with non-blocking I/O. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-TIMEOUT | a single send() operation exceeded the given timeout period |
SOCKET-SEND-ERROR | an error occurred sending the socket data |
SOCKET-SSL-ERROR | there was an SSL error while writing data to the socket |
Sends string data over the socket without converting the string to the socket's encoding, but instead is sent exactly as-is; if any errors occur, an exception is thrown.
str | string data to be sent (without any conversion to the socket's encoding) over the socket without the trailing null ('\0') character |
timeout_ms | the timeout in milliseconds (1/1000 second). If no timeout is passed, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection; the timeout value is the longest value that a single send() operation can take with non-blocking I/O. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-TIMEOUT | a single send() operation exceeded the given timeout period |
SOCKET-SEND-ERROR | an error occurred sending the socket data |
SOCKET-SSL-ERROR | there was an SSL error while writing data to the socket |
Sends binary data over the socket; if any errors occur, an exception is thrown.
bin | Sends the binary data over the socket |
timeout_ms | the timeout in milliseconds (1/1000 second). If no timeout is passed, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection; the timeout value is the longest value that a single send() operation can take with non-blocking I/O. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-TIMEOUT | a single send() operation exceeded the given timeout period |
SOCKET-SEND-ERROR | an error occurred sending the socket data |
SOCKET-SSL-ERROR | there was an SSL error while writing data to the socket |
nothing Qore::Socket::sendBinary2 | ( | string | str, |
timeout | timeout_ms = -1 |
||
) |
Sends string data over the socket without converting the string to the socket's encoding, but instead is sent exactly as-is; if any errors occur, an exception is thrown.
str | string data to be sent (without any conversion to the socket's encoding) over the socket without the trailing null ('\0') character |
timeout_ms | the timeout in milliseconds (1/1000 second). If no timeout is passed, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection; the timeout value is the longest value that a single send() operation can take with non-blocking I/O. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-TIMEOUT | a single send() operation exceeded the given timeout period |
SOCKET-SEND-ERROR | an error occurred sending the socket data |
SOCKET-SSL-ERROR | there was an SSL error while writing data to the socket |
nothing Qore::Socket::sendBinary2 | ( | binary | bin, |
timeout | timeout_ms = -1 |
||
) |
Sends binary data over the socket; if any errors occur, an exception is thrown.
bin | Sends the binary data over the socket |
timeout_ms | the timeout in milliseconds (1/1000 second). If no timeout is passed, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection; the timeout value is the longest value that a single send() operation can take with non-blocking I/O. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-TIMEOUT | a single send() operation exceeded the given timeout period |
SOCKET-SEND-ERROR | an error occurred sending the socket data |
SOCKET-SSL-ERROR | there was an SSL error while writing data to the socket |
nothing Qore::Socket::sendHTTPMessage | ( | string | method, |
string | path, | ||
string | http_version, | ||
hash | headers, | ||
*string | body, | ||
*reference | info, | ||
timeout | timeout_ms = -1 |
||
) |
Sends an HTTP message with a method and user-defined headers given as a hash and an optional message body.
Creates a properly-formatted HTTP message and sends it over the Socket. To send a string without converting the encoding to the Socket's encoding, convert the string to a binary object using the binary() function and use the variant of this method that takes a binary object for the data argument.
method | the HTTP method name to send (i.e. POST, HEAD, etc) |
path | the path component of the URL |
http_version | the HTTP protocol version ("1.0" or "1.1" ) |
headers | a hash of additional headers to send (key-value pairs) |
body | if present (and does not have a length of zero), the body to be sent with the message (if present, the "Content-Length" header will be automatically set); string data will be automatically converted to the Socket's encoding if necessary |
info | An optional reference to an lvalue that can accept a hash that will be used as an output variable with the following hash key:
|
timeout_ms | the timeout in milliseconds (1/1000 second); If no timeout is passed or is negative, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
ENCODING-CONVERSION-ERROR | the given string could not be converted to the socket's character encoding |
SOCKET-SEND-ERROR | Send failed |
SOCKET-SSL-ERROR | there was an error sending SSL data |
nothing Qore::Socket::sendHTTPMessage | ( | string | method, |
string | path, | ||
string | http_version, | ||
hash | headers, | ||
binary | body, | ||
*reference | info, | ||
timeout | timeout_ms = -1 |
||
) |
Sends an HTTP message with a method and user-defined headers given as a hash and an optional message body.
Creates a properly-formatted HTTP message and sends it over the Socket
method | the HTTP method name to send (i.e. POST, HEAD, etc) |
path | the path component of the URL |
http_version | the HTTP protocol version ("1.0" or "1.1" ) |
headers | a hash of additional headers to send (key-value pairs) |
body | if it does not have a length of zero, the body to be sent with the message (if present, the "Content-Length" header will be automatically set) |
info | An optional reference to an lvalue that can accept a hash that will be used as an output variable with the following hash key:
|
timeout_ms | the timeout in milliseconds (1/1000 second); If no timeout is passed or is negative, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SEND-ERROR | Send failed |
SOCKET-SSL-ERROR | there was an error sending SSL data |
nothing Qore::Socket::sendHTTPMessageWithCallback | ( | code | scb, |
string | method, | ||
string | path, | ||
string | http_version, | ||
hash | headers, | ||
*reference | info, | ||
timeout | timeout_ms = -1 |
||
) |
Sends an HTTP message with a method and user-defined headers given as a hash and an optional message body.
Creates a properly-formatted HTTP message and sends it over the Socket
scb | The callback giving the chunked HTTP data to send; this callback must return either a string or a binary value each time it is called to give the chunked data to send; when all data has been sent, then a hash of message trailers can be sent or simply NOTHING which will close the chunked message |
method | the HTTP method name to send (i.e. POST, HEAD, etc) |
path | the path component of the URL |
http_version | the HTTP protocol version ("1.0" or "1.1" ) |
headers | a hash of additional headers to send (key-value pairs) |
info | An optional reference to an lvalue that can accept a hash that will be used as an output variable with the following hash key:
|
timeout_ms | the timeout in milliseconds (1/1000 second); If no timeout is passed or is negative, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SEND-ERROR | Send failed |
SOCKET-SSL-ERROR | there was an error sending SSL data |
nothing Qore::Socket::sendHTTPResponse | ( | softint | status_code, |
string | status_desc, | ||
string | http_version, | ||
hash | headers, | ||
*string | body, | ||
timeout | timeout_ms = -1 |
||
) |
Sends an HTTP response with user-defined headers given as a hash and an optional message body.
Creates a properly-formatted HTTP response message and sends it over the Socket (must already be connected). If any errors occur, an exception is raised. To send a string without converting the encoding to the Socket's encoding, convert the string to a binary object using the binary() function and use the variant of this method that takes a binary object for the data argument.
status_code | the HTTP status code to send (i.e. 200 , 404 , etc) |
status_desc | the descriptive text for the status code. |
http_version | the HTTP protocol version (normally "1.0" or "1.1" , however this method allows any string to be sent) |
headers | a hash of additional headers to send (key-value pairs) |
body | if present (and does not have a length of zero), the body to be sent with the message (if present, the "Content-Length" header will be automatically set); string data will be automatically converted to the Socket's encoding if necessary |
timeout_ms | the timeout in milliseconds (1/1000 second); If no timeout is passed or is negative, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-SENDHTTPRESPONSE-STATUS-ERROR | raised if the status_code (first argument) is < 100 or > 599 |
ENCODING-CONVERSION-ERROR | the given string could not be converted to the socket's character encoding |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SEND-ERROR | send failed |
nothing Qore::Socket::sendHTTPResponse | ( | softint | status_code, |
string | status_desc, | ||
string | http_version, | ||
hash | headers, | ||
binary | body, | ||
timeout | timeout_ms = -1 |
||
) |
Sends an HTTP response with user-defined headers given as a hash and a message body as literal binary data.
Creates a properly-formatted HTTP response message and sends it over the Socket (must already be connected). If any errors occur, an exception is raised.
status_code | the HTTP status code to send (i.e. 200 , 404 , etc) |
status_desc | the descriptive text for the status code. |
http_version | the HTTP protocol version (normally "1.0" or "1.1" , however this method allows any string to be sent) |
headers | a hash of additional headers to send (key-value pairs) |
body | if the binary object given does not have a length of zero, the body to be sent with the message (if present, the "Content-Length" header will be automatically set) |
timeout_ms | the timeout in milliseconds (1/1000 second); If no timeout is passed or is negative, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-SENDHTTPRESPONSE-STATUS-ERROR | raised if the status_code (first argument) is < 100 or > 599 |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SEND-ERROR | send failed |
nothing Qore::Socket::sendHTTPResponseWithCallback | ( | code | scb, |
softint | status_code, | ||
string | status_desc, | ||
string | http_version, | ||
hash | headers, | ||
timeout | timeout_ms = -1 |
||
) |
Sends an HTTP response with user-defined headers given as a hash and a message body as literal binary data.
Creates a properly-formatted HTTP response message and sends it over the Socket (must already be connected). If any errors occur, an exception is raised.
scb | The callback giving the chunked HTTP data to send; this callback must return either a string or a binary value each time it is called to give the chunked data to send; when all data has been sent, then a hash of message trailers can be sent or simply NOTHING which will close the chunked message |
status_code | the HTTP status code to send (i.e. 200 , 404 , etc) |
status_desc | the descriptive text for the status code. |
http_version | the HTTP protocol version (normally "1.0" or "1.1" , however this method allows any string to be sent) |
headers | a hash of additional headers to send (key-value pairs) |
timeout_ms | the timeout in milliseconds (1/1000 second); If no timeout is passed or is negative, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-SENDHTTPRESPONSE-STATUS-ERROR | raised if the status_code (first argument) is < 100 or > 599 |
SOCKET-NOT-OPEN | the socket is not connected |
SOCKET-TIMEOUT | the data requested was not received in the timeout period |
SOCKET-SEND-ERROR | send failed |
int Qore::Socket::sendi1 | ( | softint | i = 0 , |
timeout | timeout_ms = -1 |
||
) |
Sends a 1-byte integer over the socket.
If any errors occur, an exception is thrown
i | the integer to send; only the least-significant byte will be sent |
timeout_ms | the timeout in milliseconds (1/1000 second). If no timeout is passed, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection; the timeout value is the longest value that a single send() operation can take with non-blocking I/O. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-TIMEOUT | a single send() operation exceeded the given timeout period |
SOCKET-SEND-ERROR | an error occurred sending the socket data |
SOCKET-SSL-ERROR | there was an SSL error while writing data to the socket |
int Qore::Socket::sendi2 | ( | softint | i = 0 , |
timeout | timeout_ms = -1 |
||
) |
Sends a 2-byte (16-bit) integer in big-endian format (network byte order) over the socket.
If any errors occur, an exception is thrown
i | the integer to send; only the least-significant 2 bytes will be sent |
timeout_ms | the timeout in milliseconds (1/1000 second). If no timeout is passed, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection; the timeout value is the longest value that a single send() operation can take with non-blocking I/O. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-TIMEOUT | a single send() operation exceeded the given timeout period |
SOCKET-SEND-ERROR | an error occurred sending the socket data |
SOCKET-SSL-ERROR | there was an SSL error while writing data to the socket |
int Qore::Socket::sendi2LSB | ( | softint | i = 0 , |
timeout | timeout_ms = -1 |
||
) |
Sends a 2-byte (16-bit) integer in little-endian format over the socket.
If any errors occur, an exception is thrown
i | the integer to send; only the least-significant 2 bytes will be sent |
timeout_ms | the timeout in milliseconds (1/1000 second). If no timeout is passed, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection; the timeout value is the longest value that a single send() operation can take with non-blocking I/O. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-TIMEOUT | a single send() operation exceeded the given timeout period |
SOCKET-SEND-ERROR | an error occurred sending the socket data |
SOCKET-SSL-ERROR | there was an SSL error while writing data to the socket |
int Qore::Socket::sendi4 | ( | softint | i = 0 , |
timeout | timeout_ms = -1 |
||
) |
Sends a 4-byte (32-bit) integer in big-endian format (network byte order) over the socket.
If any errors occur, an exception is thrown
i | the integer to send; only the least-significant 4 bytes will be sent |
timeout_ms | the timeout in milliseconds (1/1000 second). If no timeout is passed, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection; the timeout value is the longest value that a single send() operation can take with non-blocking I/O. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-TIMEOUT | a single send() operation exceeded the given timeout period |
SOCKET-SEND-ERROR | an error occurred sending the socket data |
SOCKET-SSL-ERROR | there was an SSL error while writing data to the socket |
int Qore::Socket::sendi4LSB | ( | softint | i = 0 , |
timeout | timeout_ms = -1 |
||
) |
Sends a 4-byte (32-bit) integer in little-endian format over the socket.
If any errors occur, an exception is thrown
i | the integer to send; only the least-significant 4 bytes will be sent |
timeout_ms | the timeout in milliseconds (1/1000 second). If no timeout is passed, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection; the timeout value is the longest value that a single send() operation can take with non-blocking I/O. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-TIMEOUT | a single send() operation exceeded the given timeout period |
SOCKET-SEND-ERROR | an error occurred sending the socket data |
SOCKET-SSL-ERROR | there was an SSL error while writing data to the socket |
int Qore::Socket::sendi8 | ( | softint | i = 0 , |
timeout | timeout_ms = -1 |
||
) |
Sends an 8-byte (64-bit) integer in big-endian format (network byte order) over the socket.
If any errors occur, an exception is thrown
i | the integer to send |
timeout_ms | the timeout in milliseconds (1/1000 second). If no timeout is passed, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection; the timeout value is the longest value that a single send() operation can take with non-blocking I/O. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-TIMEOUT | a single send() operation exceeded the given timeout period |
SOCKET-SEND-ERROR | an error occurred sending the socket data |
SOCKET-SSL-ERROR | there was an SSL error while writing data to the socket |
int Qore::Socket::sendi8LSB | ( | softint | i = 0 , |
timeout | timeout_ms = -1 |
||
) |
Sends an 8-byte (64-bit) integer in little-endian format over the socket.
If any errors occur, an exception is thrown
i | the integer to send |
timeout_ms | the timeout in milliseconds (1/1000 second). If no timeout is passed, then the call will not time out and will not return until all the data has been sent or the remote end closes the connection; the timeout value is the longest value that a single send() operation can take with non-blocking I/O. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
SOCKET-NOT-OPEN | The socket is not connected |
SOCKET-TIMEOUT | a single send() operation exceeded the given timeout period |
SOCKET-SEND-ERROR | an error occurred sending the socket data |
SOCKET-SSL-ERROR | there was an SSL error while writing data to the socket |
nothing Qore::Socket::setCertificate | ( | SSLCertificate | cert | ) |
Sets the X.509 certificate to use for negotiating encrypted connections.
cert | This must be an SSLCertificate object |
nothing Qore::Socket::setCertificate | ( | string | cert_pem | ) |
Sets the X.509 certificate to use for negotiating encrypted connections from the PEM-encoded string representing the X.509 certificate.
cert_pem | the PEM-encoded string representing the X.509 certificate |
nothing Qore::Socket::setCertificate | ( | binary | cert_der | ) |
Sets the X.509 certificate to use for negotiating encrypted connections from the DER-encoded binary object representing the X.509 certificate.
cert_der | the DER-encoded binary object representing the X.509 certificate |
nothing Qore::Socket::setCharset | ( | string | encoding | ) |
Sets the character encoding for the socket.
A method synonym for Socket::setEncoding(), kept for backwards-compatibility
encoding | The character encoding for the socket |
nothing Qore::Socket::setEncoding | ( | string | encoding | ) |
Sets the character encoding for the socket.
encoding | the character encoding for the socket |
nothing Qore::Socket::setEventQueue | ( | ) |
Removes any Queue object from the Socket object so that socket events are no longer added to the Queue.
nothing Qore::Socket::setEventQueue | ( | Queue | queue | ) |
Sets a Queue object to receive socket events.
queue | the Queue object to receive socket events; note that the Queue passed cannot have any maximum size set or a QUEUE-ERROR will be thrown |
QUEUE-ERROR | the Queue passed has a maximum size set |
Sets the boolean TCP_NODELAY
setting for the socket.
When this setting is True, then data will be immediately sent out over the socket, when it is False, then data transmission may be delayed to be packaged with other data for the same target.
Delayed data transmissions may cause problems when the sender immediately closes the socket after sending data; in this case the receiver may not get the data even though the send succeeded.
Note that if no value is given to the method, the argument will be assumed to be True, and output buffering will be turned off for the socket.
nd | the boolean TCP_NODELAY setting for the socket |
nothing Qore::Socket::setPrivateKey | ( | SSLPrivateKey | key | ) |
Sets the private key to use for negotiating encrypted connections along with the X.509 certificate.
key | the private key for the X.509 certificate to use when establishing TLS/SSL encrypted connections |
Sets the private key to use for negotiating encrypted connections along with the X.509 certificate from a PEM-encoded string representing the private key and an optional password.
key_pem | the PEM-encoded string representing the private key for the X.509 certificate to use when establishing TLS/SSL encrypted connections |
pass | the password for the private key, if needed |
nothing Qore::Socket::setPrivateKey | ( | binary | key_der | ) |
Sets the private key to use for negotiating encrypted connections along with the X.509 certificate from a DER-encoded binary object representing the private key.
key_der | the DER-encoded binary object representing the private key for the X.509 certificate to use when establishing TLS/SSL encrypted connections |
int Qore::Socket::setRecvTimeout | ( | timeout | timeout_ms | ) |
sets the receive timeout as a socket option
Returns 0 for success, -1 for error (check errno() for the actual error in this case)
timeout_ms | the receive timeout to set with a resolution of milliseconds; Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.) |
int Qore::Socket::setSendTimeout | ( | timeout | timeout_ms | ) |
nothing Qore::Socket::setWarningQueue | ( | int | warning_ms, |
int | warning_bs, | ||
Queue | queue, | ||
any | arg, | ||
timeout | min_ms = 1s |
||
) |
Sets a Queue object to receive socket warnings.
warning_ms | the threshold in milliseconds for individual socket actions (send, receive, connect), if exceeded, a socket warning is placed on the warning queue with the following keys:
|
warning_bs | value in bytes per second; if any call has performance below this threshold, a socket warning is placed on the warning queue with the following keys:
|
queue | the Queue object to receive warning events |
arg | an optional argument to be placed in the "arg" key in each warning hash (could be used to identify the socket for example) |
min_ms | the minimum transfer time with a resolution of milliseconds for a transfer to be eligible for triggering a warning; transfers that take less than this period of time are not eligible for raising a warning |
QUEUE-ERROR | the Queue passed has a maximum size set |
SOCKET-SETWARNINGQUEUE-ERROR | at least one of warning_ms and warning_bs must be > 0 |
int Qore::Socket::shutdown | ( | ) |
nothing Qore::Socket::shutdownSSL | ( | ) |
Shuts down the SSL connection on a secure connection.
If any errors occur, an exception is raised
SOCKET-SSL-ERROR | an error occurred shutting down the TLS/SSL connection |
nothing Qore::Socket::upgradeClientToSSL | ( | ) |
Upgrades a client socket connection to a TLS/SSL connection.
nothing Qore::Socket::upgradeServerToSSL | ( | ) |
Upgrades a server socket connection to a TLS/SSL connection.
*string Qore::Socket::verifyPeerCertificate | ( | ) |
Returns a string code giving the result of verifying the remote certificate or NOTHING if an encrypted connection is not currently established.