347 |
try |
try |
348 |
{ |
{ |
349 |
getImpl().bind (tmp.getAddress(), tmp.getPort()); |
getImpl().bind (tmp.getAddress(), tmp.getPort()); |
|
bound = true; |
|
350 |
} |
} |
351 |
catch (IOException exception) |
catch (IOException exception) |
352 |
{ |
{ |
443 |
*/ |
*/ |
444 |
public InetAddress getInetAddress () |
public InetAddress getInetAddress () |
445 |
{ |
{ |
446 |
return getImpl().getInetAddress(); |
try |
447 |
|
{ |
448 |
|
return getImpl().getInetAddress(); |
449 |
|
} |
450 |
|
catch (SocketException e) |
451 |
|
{ |
452 |
|
// This cannot happen as we are connected. |
453 |
|
} |
454 |
|
|
455 |
|
return null; |
456 |
} |
} |
457 |
|
|
458 |
/** |
/** |
466 |
public InetAddress getLocalAddress () |
public InetAddress getLocalAddress () |
467 |
{ |
{ |
468 |
InetAddress addr = null; |
InetAddress addr = null; |
469 |
|
|
470 |
try |
try |
471 |
{ |
{ |
472 |
addr = (InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR); |
addr = (InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR); |
499 |
*/ |
*/ |
500 |
public int getPort () |
public int getPort () |
501 |
{ |
{ |
502 |
if (impl != null) |
try |
503 |
return getImpl().getPort(); |
{ |
504 |
|
if (getImpl() != null) |
505 |
|
return getImpl().getPort(); |
506 |
|
} |
507 |
|
catch (SocketException e) |
508 |
|
{ |
509 |
|
// This cannot happen as we are connected. |
510 |
|
} |
511 |
|
|
512 |
return -1; |
return -1; |
513 |
} |
} |
520 |
*/ |
*/ |
521 |
public int getLocalPort () |
public int getLocalPort () |
522 |
{ |
{ |
523 |
if (impl != null) |
try |
524 |
return getImpl().getLocalPort(); |
{ |
525 |
|
if (getImpl() != null) |
526 |
|
return getImpl().getLocalPort(); |
527 |
|
} |
528 |
|
catch (SocketException e) |
529 |
|
{ |
530 |
|
// This cannot happen as we are bound. |
531 |
|
} |
532 |
|
|
533 |
return -1; |
return -1; |
534 |
} |
} |
541 |
*/ |
*/ |
542 |
public SocketAddress getLocalSocketAddress() |
public SocketAddress getLocalSocketAddress() |
543 |
{ |
{ |
544 |
InetAddress addr = getLocalAddress (); |
if (!isBound()) |
|
|
|
|
if (addr == null) |
|
545 |
return null; |
return null; |
546 |
|
|
547 |
return new InetSocketAddress (addr, getImpl().getLocalPort()); |
InetAddress addr = getLocalAddress (); |
548 |
|
|
549 |
|
try |
550 |
|
{ |
551 |
|
return new InetSocketAddress (addr, getImpl().getLocalPort()); |
552 |
|
} |
553 |
|
catch (SocketException e) |
554 |
|
{ |
555 |
|
// This cannot happen as we are bound. |
556 |
|
return null; |
557 |
|
} |
558 |
} |
} |
559 |
|
|
560 |
/** |
/** |
568 |
if (!isConnected ()) |
if (!isConnected ()) |
569 |
return null; |
return null; |
570 |
|
|
571 |
return new InetSocketAddress(getImpl().getInetAddress (), getImpl().getPort ()); |
try |
572 |
|
{ |
573 |
|
return new InetSocketAddress (getImpl().getInetAddress (), getImpl().getPort ()); |
574 |
|
} |
575 |
|
catch (SocketException e) |
576 |
|
{ |
577 |
|
// This cannot happen as we are connected. |
578 |
|
return null; |
579 |
|
} |
580 |
} |
} |
581 |
|
|
582 |
/** |
/** |
1107 |
*/ |
*/ |
1108 |
public boolean isConnected () |
public boolean isConnected () |
1109 |
{ |
{ |
1110 |
return getImpl().getInetAddress () != null; |
try |
1111 |
|
{ |
1112 |
|
return getImpl().getInetAddress () != null; |
1113 |
|
} |
1114 |
|
catch (SocketException e) |
1115 |
|
{ |
1116 |
|
return false; |
1117 |
|
} |
1118 |
} |
} |
1119 |
|
|
1120 |
/** |
/** |