Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

class method

Socket.getservbyport

(::Integer service_port) -> ::String
(::Integer service_port, ::String layer4_proto) -> ::String
Socket.getservbyport(port [, protocol_name]) => service

Obtains the port number for port.

If protocol_name is not given, “tcp” is assumed.

Example
Socket.getservbyport(80)         #=> "www"
Socket.getservbyport(514, "tcp") #=> "shell"
Socket.getservbyport(514, "udp") #=> "syslog"