use of java.net.SocketAddress in project robovm by robovm.
the class IoBridge method getSocketLocalAddress.
public static InetAddress getSocketLocalAddress(FileDescriptor fd) throws SocketException {
try {
SocketAddress sa = Libcore.os.getsockname(fd);
InetSocketAddress isa = (InetSocketAddress) sa;
return isa.getAddress();
} catch (ErrnoException errnoException) {
throw errnoException.rethrowAsSocketException();
}
}
use of java.net.SocketAddress in project robovm by robovm.
the class RouteSelector method resetNextInetSocketAddress.
/** Resets {@link #nextInetSocketAddress} to the first option. */
private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException {
// Clear the addresses. Necessary if getAllByName() below throws!
socketAddresses = null;
String socketHost;
if (proxy.type() == Proxy.Type.DIRECT) {
socketHost = uri.getHost();
socketPort = getEffectivePort(uri);
} else {
SocketAddress proxyAddress = proxy.address();
if (!(proxyAddress instanceof InetSocketAddress)) {
throw new IllegalArgumentException("Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass());
}
InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress;
socketHost = proxySocketAddress.getHostName();
socketPort = proxySocketAddress.getPort();
}
// Try each address for best behavior in mixed IPv4/IPv6 environments.
socketAddresses = dns.getAllByName(socketHost);
nextSocketAddressIndex = 0;
}
use of java.net.SocketAddress in project robovm by robovm.
the class SocketChannelTest method testCFII_UnsupportedType.
public void testCFII_UnsupportedType() throws Exception {
class SubSocketAddress extends SocketAddress {
private static final long serialVersionUID = 1L;
//empty
public SubSocketAddress() {
super();
}
}
statusNotConnected_NotPending();
SocketAddress newTypeAddress = new SubSocketAddress();
try {
this.channel1.connect(newTypeAddress);
fail("Should throw an UnsupportedAddressTypeException here.");
} catch (UnsupportedAddressTypeException e) {
// OK.
}
}
use of java.net.SocketAddress in project robovm by robovm.
the class SocketChannelTest method test_finishConnect.
/**
* Regression test for Harmony-1947.
*/
public void test_finishConnect() throws Exception {
SocketAddress address = new InetSocketAddress("localhost", 0);
ServerSocketChannel theServerChannel = ServerSocketChannel.open();
ServerSocket serversocket = theServerChannel.socket();
serversocket.setReuseAddress(true);
// Bind the socket
serversocket.bind(address);
boolean doneNonBlockingConnect = false;
// Loop so that we make sure we're definitely testing finishConnect()
while (!doneNonBlockingConnect) {
channel1 = SocketChannel.open();
// Set the SocketChannel to non-blocking so that connect(..) does
// not block
channel1.configureBlocking(false);
boolean connected = channel1.connect(new InetSocketAddress("localhost", serversocket.getLocalPort()));
if (!connected) {
// Now set the SocketChannel back to blocking so that
// finishConnect() blocks.
channel1.configureBlocking(true);
doneNonBlockingConnect = channel1.finishConnect();
}
if (doneNonBlockingConnect) {
tryFinish();
}
channel1.close();
}
if (!serversocket.isClosed()) {
serversocket.close();
}
}
use of java.net.SocketAddress in project robovm by robovm.
the class OldSocketChannelTest method testOpenSocketAddress.
public void testOpenSocketAddress() throws IOException {
this.channel1 = SocketChannel.open(localAddr1);
assertTrue(this.channel1.isConnected());
SocketAddress newTypeAddress = new SubSocketAddress();
try {
this.channel1 = SocketChannel.open(newTypeAddress);
fail("Should throw UnexpectedAddressTypeException");
} catch (UnsupportedAddressTypeException e) {
// expected
}
SocketAddress unresolvedAddress = InetSocketAddress.createUnresolved("127.0.0.1", 8080);
try {
this.channel1 = SocketChannel.open(unresolvedAddress);
fail("Should throw UnresolvedAddressException");
} catch (UnresolvedAddressException e) {
// expected
}
SocketChannel channel1IP = null;
try {
channel1IP = SocketChannel.open(null);
fail("Should throw an IllegalArgumentException");
} catch (IllegalArgumentException e) {
// correct
}
assertNull(channel1IP);
}
Aggregations