Skip to content

JDWX DNSQuery Network Socket

JDW edited this page Jul 17, 2022 · 1 revision

JDWX\DNSQuery\Network\Socket

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

Constants

SOCK_STREAM

const SOCK_STREAM = SOCK_STREAM

SOCK_DGRAM

const SOCK_DGRAM = SOCK_DGRAM

Properties

lastError

public  lastError
  • Visibility: public

dateCreated

public  dateCreated
  • Visibility: public

dateLastUsed

public  dateLastUsed
  • Visibility: public

sock

private  sock = null
  • Visibility: private

type

private  type
  • Visibility: private

remoteAddress

private  remoteAddress
  • Visibility: private

remotePort

private  remotePort
  • Visibility: private

timeout

private  timeout
  • Visibility: private

timeoutSeconds

private  timeoutSeconds
  • Visibility: private

timeoutMicroseconds

private  timeoutMicroseconds
  • Visibility: private

localAddress

private  localAddress = null
  • Visibility: private

localPort

private  localPort = null
  • Visibility: private

Methods

__construct

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

Arguments

  • 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

__destruct

mixed JDWX\DNSQuery\Network\Socket::__destruct()

Destructor to make sure the socket gets closed.

  • Visibility: public

bindAddress

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

Arguments

  • 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

close

void JDWX\DNSQuery\Network\Socket::close()

Close the socket connection to the DNS server

  • Visibility: public

open

bool JDWX\DNSQuery\Network\Socket::open()

Open a socket connection to the DNS server

  • Visibility: public

read

bool|string JDWX\DNSQuery\Network\Socket::read(int o_size, int i_maxSize)

Read a response from a DNS server

  • Visibility: public

Arguments

  • o_size int - (output) The size of the DNS packet read is passed back
  • i_maxSize int - Max data size that the caller wants

write

bool JDWX\DNSQuery\Network\Socket::write(string i_data)

writes the given string to the DNS server socket

  • Visibility: public

Arguments

  • i_data string - Binary packed data representing a DNS packet
Clone this wiki locally