Socket methods

  • new(domain, type, protocol): creates a new socket with domain (AF_UNIX or AF_INET), type (one of SOCK_* below) and protocol (usually 0)
  • connect(host, port): connects to the server located at host port port.
  • read(bytes): read up to bytes from the socket and return a string containing what was read
  • readline: read a single line from the socket, up to a newline (or until the socket's been closed)
  • write(string): write the string specified by string to the socket
  • close: close the connection to the client or server
  • listen(host, port): listens for connections on port, using the IP address or host name given by host if provided (else it listens on all network interfaces)
  • accept: accepts a connection on a listening socket. Returns a list containing the following three items, in order: the socket corresponding to the just accepted client, the client's IP address and the client's port

Constants

  • AF_UNIX: Unix domain sockets
  • AF_INET: Internet (TCP/IP) domain sockets
  • SOCK_STREAM: Usually a TCP connection
  • SOCK_DGRAM: Usually a UDP connection/datagram
  • SOCK_RAW: A raw socket, usually for sending hand-crafted TCP/IP packets
  • SOCK_SEQPACKET: Sequenced packet stream
  • SOCK_RDM: Reliably delivered socket