Java™ Platform
Standard Ed. 8
compact1, compact2, compact3
java.net
Class InetSocketAddress
-
-
Constructor Summary
Constructors
| Constructor |
Description |
InetSocketAddress(InetAddress addr,
int port) |
Creates a socket address from an IP address and a port number.
|
InetSocketAddress(int port) |
Creates a socket address where the IP address is the wildcard address
and the port number a specified value.
|
InetSocketAddress(String hostname,
int port) |
Creates a socket address from a hostname and a port number.
|
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods
| Modifier and Type |
Method |
Description |
static InetSocketAddress |
createUnresolved(String host,
int port) |
Creates an unresolved socket address from a hostname and a port number.
|
boolean |
equals(Object obj) |
Compares this object against the specified object.
|
InetAddress |
getAddress() |
Gets the InetAddress.
|
String |
getHostName() |
Gets the hostname.
|
String |
getHostString() |
Returns the hostname, or the String form of the address if it
doesn't have a hostname (it was created using a literal).
|
int |
getPort() |
Gets the port number.
|
int |
hashCode() |
Returns a hashcode for this socket address.
|
boolean |
isUnresolved() |
Checks whether the address has been resolved or not.
|
String |
toString() |
Constructs a string representation of this InetSocketAddress.
|
-
-
Method Detail
-
getHostString
public final String getHostString()
Returns the hostname, or the String form of the address if it
doesn't have a hostname (it was created using a literal).
This has the benefit of not attempting a reverse lookup.
- Returns:
- the hostname, or String representation of the address.
- Since:
- 1.7
Java™ Platform
Standard Ed. 8
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.