InetSocketAddress
Object Hierarchy:
Description:
[ CCode ( type_id = "g_inet_socket_address_get_type ()" ) ]
public class InetSocketAddress : SocketAddress, SocketConnectable
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
All known sub-classes:
Namespace: GLib
Package: gio-2.0
Content:
Properties:
Creation methods:
Methods:
Inherited Members:
All known members inherited from class GLib.SocketAddress
All known members inherited from class GLib.Object
All known members inherited from interface GLib.SocketConnectable