Ruby Socket Functions
EditRocket provides the following information on Socket functions in the Ruby source code builder.
accept - Accepts an incoming connection returning an array containing a new Socket object and a string holding the struct sockaddr information about the caller.
accept_nonblock - Accepts an incoming connection using accept(2) after O_NONBLOCK is set for the underlying file descriptor. It returns an array containg the accpeted socket for the incoming connection, client_socket, and a string that contains the struct sockaddr information about the caller, client_sockaddr.
bind(server_sockaddr) - Binds to the given struct sockaddr.
connect(server_sockaddr) - Requests a connection to be made on the given server_sockaddr. Returns 0 if successful, otherwise an exception is raised.
connect_nonblock(server_sockaddr) - Requests a connection to be made on the given server_sockaddr after O_NONBLOCK is set for the underlying file descriptor. Returns 0 if successful, otherwise an exception is raised.
getaddrinfo" Socket.getaddrinfo(host, service, family=nil, socktype=nil, protocol=nil, flags=nil) - Return address information for host and port. The remaining arguments are hints that limit the address information returned.
gethostbyname" Socket.gethostbyname(host) - Resolve host and return name and address information for it, similarly to gethostbyname(3). host can be a domain name or the presentation format of an address.
getservbyname" Socket.getservbyname(name, proto=\"tcp\") - name is a service name ("ftp", "telnet", ...) and proto is a protocol name ("udp", "tcp", ...). '/etc/services' (or your system's equivalent) is searched for a service for name and proto, and the port number is returned.
listen( int ) - Listens for connections, using the specified int as the backlog. A call to listen only applies if the socket is of type SOCK_STREAM or SOCK_SEQPACKET.
recvfrom(maxlen) - Receives up to maxlen bytes from socket. flags is zero or more of the MSG_ options. The first element of the results, mesg, is the data received. The second element, sender_sockaddr, contains protocol-specific information on the sender.
recvfrom_nonblock(maxlen) - Receives up to maxlen bytes from socket using recvfrom(2) after O_NONBLOCK is set for the underlying file descriptor. flags is zero or more of the MSG_ options. The first element of the results, mesg, is the data received. The second element, sender_sockaddr, contains protocol-specific information on the sender.
sysaccept - Accepts an incoming connection returnings an array containg the (integer) file descriptor for the incoming connection, client_socket_fd, and a string that contains the struct sockaddr information about the caller, client_sockaddr.