InetSocketAddress
Object Hierarchy:
Description:
[
CCode ( type_id =
"g_inet_socket_address_get_type ()" ) ]
public class InetSocketAddress :
SocketAddress,
SocketConnectable
An IPv4 or IPv6 socket address.
That is, the combination of a [class@Gio.InetAddress] and a port number.
In UNIX terms, `GInetSocketAddress` corresponds to a [`struct sockaddr_in` or `struct sockaddr_in6`](man:sockaddr(3type)).
Example: InetSocketAddress:
public static void http_request (InetSocketAddress socket_address, string host) {
try {
// Connect:
SocketClient client = new SocketClient ();
SocketConnection conn = client.connect (socket_address);
// Send HTTP GET request
string message = @"GET / HTTP/1.1\r\nHost: %s\r\n\r\n".printf (host);
conn.output_stream.write (message.data);
// Receive response
DataInputStream response = new DataInputStream (conn.input_stream);
string status_line = response.read_line (null).strip ();
print ("Received status line: %s\n", status_line);
} catch (Error e) {
print ("Error: %s\n", e.message);
}
}
public static int main (string[] args) {
// Example 1:
InetAddress address1 = new InetAddress.from_bytes ({208, 80, 152, 201}, SocketFamily.IPV4);
InetSocketAddress socket_address1 = new InetSocketAddress (address1, 80);
http_request (socket_address1, "www.wikipedia.org");
// Example 2:
InetAddress address2 = new InetAddress.from_string ("208.80.152.201");
InetSocketAddress socket_address2 = new InetSocketAddress (address2, 80);
http_request (socket_address2, "www.wikipedia.org");
// Example 3:
try {
Resolver resolver = Resolver.get_default ();
List<InetAddress> addresses = resolver.lookup_by_name ("www.valadoc.org", null);
foreach (InetAddress address3 in addresses) {
InetSocketAddress socket_address3 = new InetSocketAddress (address2, 80);
http_request (socket_address3, "www.valadoc.org");
}
} catch (Error e) {
print ("Error: %s\n", e.message);
}
return 0;
}
valac --pkg gio-2.0 GLib.InetSocketAddress.vala
Content:
Properties:
- public InetAddress address { get; construct; }
The address.
- public uint flowinfo { get; construct; }
The `sin6_flowinfo` field, for IPv6 addresses.
- public uint port { get; construct; }
The port.
- public uint scope_id { get; construct; }
The `sin6_scope_id` field, for IPv6 addresses.
Creation methods:
Methods:
- public unowned InetAddress get_address ()
- public uint32 get_flowinfo ()
Gets the `sin6_flowinfo` field from this
, which must be an IPv6 address.
- public uint16 get_port ()
Gets this's port.
- public uint32 get_scope_id ()
Gets the `sin6_scope_id` field from this
, which must be an IPv6 address.
Inherited Members:
All known members inherited from class GLib.SocketAddress
All known members inherited from class GLib.Object
- @get
- @new
- @ref
- @set
- add_toggle_ref
- add_weak_pointer
- bind_property
- connect
- constructed
- disconnect
- dispose
- dup_data
- dup_qdata
- force_floating
- freeze_notify
- get_class
- get_data
- get_property
- get_qdata
- get_type
- getv
- interface_find_property
- interface_install_property
- interface_list_properties
- is_floating
- new_valist
- new_with_properties
- newv
- notify
- notify_property
- ref_count
- ref_sink
- remove_toggle_ref
- remove_weak_pointer
- replace_data
- replace_qdata
- set_data
- set_data_full
- set_property
- set_qdata
- set_qdata_full
- set_valist
- setv
- steal_data
- steal_qdata
- thaw_notify
- unref
- watch_closure
- weak_ref
- weak_unref
All known members inherited from interface GLib.SocketConnectable