indexing description: "[ Representation of an internet socket address which consists of an internet address and a port. This class uses IPv4 internet addresses since there is no SDL network implementation that supports IPv6 at the moment. ]" date: "$Date$" revision: "$Revision$" class EM_INET_SOCKET_ADDRESS inherit EM_INET_ADDRESS redefine to_hex_string end EM_NETWORK_HELPER_FUNCTIONS export {NONE} all end EM_NETWORK_CONSTANTS export {NONE} all end EM_SHARED_SUBSYSTEMS export {NONE} all end SDL_NET_FUNCTIONS_EXTERNAL export {NONE} all end create make_local_by_port, make_by_hostname_port, make_by_ip_port, make_by_ip_string_port, make_by_inet_address_port create {EM_SIMPLE_UDP_SOCKET, EM_UDP_PACKET, EM_SOCKET} make_by_struct feature {NONE} -- Initialization make_by_struct(an_ip_address_struct: IPADDRESS_STRUCT) is -- Create a new IPv4 socket address from `an_ip_address_struct' require an_ip_address_struct_not_void: an_ip_address_struct /= Void do create hostname.make_empty create ip_address_struct.make_new_unshared ip_address_struct.set_host (an_ip_address_struct.host) ip_address_struct.set_port (an_ip_address_struct.port) ensure host_ip_set: host_ip = convert_from_big_endian_32 (an_ip_address_struct.host) port_set: port = convert_from_big_endian_16 (an_ip_address_struct.port) end make_local_by_port (a_port: INTEGER) is -- Creates a new IPv4 socket address for all local network interfaces. require networking_enabled: network_subsystem.is_enabled port_in_range: a_port >= 0 and a_port <= 65535 do make_local ip_address_struct.set_port (convert_to_big_endian_16 (a_port)) ensure port_set: port = a_port end make_by_hostname_port (a_host: STRING; a_port: INTEGER) is -- Creates a new IPv4 socket address -- `a_host' can be a full qualified hostname or an IPv4 address -- in textual representation (x.x.x.x). require networking_enabled: network_subsystem.is_enabled host_not_void: a_host /= Void port_in_range: a_port >= 0 and a_port <= 65535 do make_by_hostname (a_host) ip_address_struct.set_port (convert_to_big_endian_16 (a_port)) ensure hostname_set: hostname = a_host port_set: port = a_port end make_by_ip_port (a_host_ip: INTEGER; a_port: INTEGER) is -- Creates a new IPv4 socket address based on `a_host_ip'. -- This tries to reverse resolve `a_host_ip' to a hostname. -- If this fails, `hostname' will be an empty string. require networking_enabled: network_subsystem.is_enabled port_in_range: a_port >= 0 and a_port <= 65535 do make_by_ip (a_host_ip) ip_address_struct.set_port (convert_to_big_endian_16 (a_port)) ensure address_set: host_ip = a_host_ip port_set: port = a_port end make_by_ip_string_port (a_host_ip_string: STRING; a_port: INTEGER) is -- Creates a new IPv4 address from `a_host_ip_string' -- Does not reverse resolve `a_host_ip_string'. require a_host_ip_string_not_void: a_host_ip_string /= Void port_in_range: a_port >= 0 and a_port <= 65535 do make_by_ip_string (a_host_ip_string) ip_address_struct.set_port (convert_to_big_endian_16 (a_port)) ensure no_error_occured: True port_set: a_port = port end make_by_inet_address_port (an_inet_address: EM_INET_ADDRESS; a_port: INTEGER) is -- Create a new inet socket address. require an_inet_address_not_void: an_inet_address /= Void port_in_range: a_port >= 0 and a_port <= 65535 do create resolve_finished_event create ip_address_struct.make_new_unshared hostname := an_inet_address.hostname.twin ip_address_struct.set_host (convert_to_big_endian_32(an_inet_address.host_ip)) ip_address_struct.set_port (convert_to_big_endian_16 (a_port)) ensure hostname_set: hostname.is_equal (an_inet_address.hostname) host_ip_set: host_ip = an_inet_address.host_ip port_set: port = a_port end feature -- Access port: INTEGER is -- The port of the socket address. do Result := convert_from_big_endian_16 (ip_address_struct.port) end feature -- Conversion to_hex_string: STRING is -- Hexadezimal represenatation of ip and port do Result := Precursor + port.to_integer_16.to_hex_string end host_ip_port_as_string: STRING is -- Host IP and port in textual representation (xy.xy.xy.xy:port) do Result := host_ip_as_string+":"+port.out end invariant port_in_range: port >= 0 and port <= 65535 end