forked from mikepultz/netdns2
-
Notifications
You must be signed in to change notification settings - Fork 1
JDWX DNSQuery Network Socket
JDW edited this page Jul 17, 2022
·
1 revision
Network socket management using PHP streams.
By and large this class returns true on success and false on failure rather than throwing exceptions because there are many cases in which a failure is not exceptional. (For example, if we have been provided a list of name servers and we fail to connect to one, we want to try the next one, not abort.)
- Class name: Socket
- Namespace: \JDWX\DNSQuery\Network
const SOCK_STREAM = SOCK_STREAM
const SOCK_DGRAM = SOCK_DGRAM
public lastError
- Visibility: public
public dateCreated
- Visibility: public
public dateLastUsed
- Visibility: public
private sock = null
- Visibility: private
private type
- Visibility: private
private remoteAddress
- Visibility: private
private remotePort
- Visibility: private
private timeout
- Visibility: private
private timeoutSeconds
- Visibility: private
private timeoutMicroseconds
- Visibility: private
private localAddress = null
- Visibility: private
private localPort = null
- Visibility: private
mixed JDWX\DNSQuery\Network\Socket::__construct(int i_type, string i_remoteAddress, int i_remotePort, float i_timeout)
constructor - set the port details
- Visibility: public
- i_type int - Type of socket to use (i.e., Socket::SOCK_DGRAM or Socket::SOCK_STREAM)
- i_remoteAddress string - IP address to connect to
- i_remotePort int - IP port to connect to
- i_timeout float - Timeout value (in seconds) to use for socket functions
mixed JDWX\DNSQuery\Network\Socket::__destruct()
Destructor to make sure the socket gets closed.
- Visibility: public
void JDWX\DNSQuery\Network\Socket::bindAddress(?string i_localAddress, ?int i_localPort)
sets the local address/port for the socket to bind to
- Visibility: public
- i_localAddress ?string - Local IP address to bind to or null to let the OS choose
- i_localPort ?int - Local IP port to bind to, or null to let the OS choose
void JDWX\DNSQuery\Network\Socket::close()
Close the socket connection to the DNS server
- Visibility: public
bool JDWX\DNSQuery\Network\Socket::open()
Open a socket connection to the DNS server
- Visibility: public
bool|string JDWX\DNSQuery\Network\Socket::read(int o_size, int i_maxSize)
Read a response from a DNS server
- Visibility: public
- o_size int - (output) The size of the DNS packet read is passed back
- i_maxSize int - Max data size that the caller wants
bool JDWX\DNSQuery\Network\Socket::write(string i_data)
writes the given string to the DNS server socket
- Visibility: public
- i_data string - Binary packed data representing a DNS packet