- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用一个使用开源 java 库 (Calimero) 的 Android 应用程序。我的代码尝试使用以下代码获取主机名和端口:
private static KNXNetworkLinkIP connect(InetSocketAddress isaLocalEP, InetSocketAddress isaRemoteEP)
{
KNXNetworkLinkIP netLinkIp = null;
int serviceMode = KNXNetworkLinkIP.TUNNEL; // tunnel to IP router
boolean useNAT = true; // NAT not used for PC true or false , but needed for emulator = true
KNXMediumSettings tpSettings = new TPSettings(true); // TP1 medium
try
{
// Output the local end point address
if (m_debugOutput == true)
{
System.out.println("..Tunneling, NAT ignored, TP1 medium");
// Should be the PC's VPN address
System.out.print("..Local EP:");
System.out.println(isaLocalEP.getHostName() + ":" + isaLocalEP.getPort());
System.out.print("..Remote EP:");
System.out.println(isaRemoteEP.getHostName() + ":" + isaRemoteEP.getPort());
System.out.print("..useNAT:");
System.out.println(useNAT);
System.out.println();
}
netLinkIp = new KNXNetworkLinkIP(serviceMode, isaLocalEP, isaRemoteEP, useNAT, tpSettings);
}
catch (KNXLinkClosedException e)
{
System.out.println("connect:KNXLinkClosedException = " + e.getMessage());
}
catch (KNXFormatException e)
{
System.out.println("connect:KNXFormatException = " + e.getMessage());
}
catch (KNXException e)
{
System.out.println("connect:KNXException = " + e.getMessage());
}
catch (Exception e)
{
System.out.println("connect:Exception = " + e.getMessage());
}
return netLinkIp;
} // connect(isaLocalEP, isaRemoteEP)
问题出在这一行:
netLinkIp = new KNXNetworkLinkIP(serviceMode, isaLocalEP, isaRemoteEP, useNAT, tpSettings);
这里是 KNXNetworkLinkIP 的代码
/*
Calimero - A library for KNX network access
Copyright (C) 2006-2008 W. Kastner
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package tuwien.auto.calimero.link;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import tuwien.auto.calimero.CloseEvent;
import tuwien.auto.calimero.FrameEvent;
import tuwien.auto.calimero.GroupAddress;
import tuwien.auto.calimero.IndividualAddress;
import tuwien.auto.calimero.KNXAddress;
import tuwien.auto.calimero.Priority;
import tuwien.auto.calimero.cemi.CEMIFactory;
import tuwien.auto.calimero.cemi.CEMILData;
import tuwien.auto.calimero.cemi.CEMILDataEx;
import tuwien.auto.calimero.exception.KNXException;
import tuwien.auto.calimero.exception.KNXIllegalArgumentException;
import tuwien.auto.calimero.exception.KNXTimeoutException;
import tuwien.auto.calimero.knxnetip.KNXConnectionClosedException;
import tuwien.auto.calimero.knxnetip.KNXnetIPConnection;
import tuwien.auto.calimero.knxnetip.KNXnetIPRouter;
import tuwien.auto.calimero.knxnetip.KNXnetIPTunnel;
import tuwien.auto.calimero.link.event.NetworkLinkListener;
import tuwien.auto.calimero.link.medium.KNXMediumSettings;
import tuwien.auto.calimero.link.medium.PLSettings;
import tuwien.auto.calimero.link.medium.RFSettings;
import tuwien.auto.calimero.link.medium.TPSettings;
import tuwien.auto.calimero.log.LogManager;
import tuwien.auto.calimero.log.LogService;
/**
* Implementation of the KNX network link based on the KNXnet/IP protocol, using a
* {@link KNXnetIPConnection}.
* <p>
* Once a link has been closed, it is not available for further link communication, i.e.
* it can't be reopened.
* <p>
* If KNXnet/IP routing is used as base protocol, the send methods with wait for
* confirmation behave equally like without wait specified, since routing is an
* unconfirmed protocol. This implies that no confirmation frames are generated, thus
* {@link NetworkLinkListener#confirmation(FrameEvent)} is not used.
* <p>
* IP address considerations:<br>
* On more IP addresses assigned to the local host (on possibly several local network
* interfaces), the default chosen local host address can differ from the expected. In
* this situation, the local endpoint has to be specified manually during instantiation.
* <br>
* Network Address Translation (NAT) aware communication can only be used, if the
* KNXnet/IP server of the remote endpoint supports it. Otherwise, connection timeouts
* will occur. With NAT enabled, KNXnet/IP accepts IPv6 addresses. By default, the
* KNXnet/IP protocol only works with IPv4 addresses.<br>
*
* @author B. Malinowsky
*/
public class KNXNetworkLinkIP implements KNXNetworkLink
{
/**
* Service mode for link layer tunneling.
* <p>
*/
public static final int TUNNEL = 1;
/**
* Service mode for routing.
* <p>
*/
public static final int ROUTER = 2;
private static final class LinkNotifier extends EventNotifier
{
LinkNotifier(Object source, LogService logger)
{
super(source, logger);
}
public void frameReceived(FrameEvent e)
{
final int mc = e.getFrame().getMessageCode();
if (mc == CEMILData.MC_LDATA_IND) {
addEvent(new Indication(new FrameEvent(source, e.getFrame())));
logger.info("indication from " + ((CEMILData) e.getFrame()).getSource());
}
else if (mc == CEMILData.MC_LDATA_CON) {
addEvent(new Confirmation(new FrameEvent(source, e.getFrame())));
logger.info("confirmation of "
+ ((CEMILData) e.getFrame()).getDestination());
}
else
logger.warn("unspecified frame event - ignored, msg code = 0x"
+ Integer.toHexString(mc));
}
public void connectionClosed(CloseEvent e)
{
((KNXNetworkLinkIP) source).closed = true;
super.connectionClosed(e);
logger.info("link closed");
LogManager.getManager().removeLogService(logger.getName());
}
};
private final int mode;
private volatile boolean closed;
private final KNXnetIPConnection conn;
private volatile byte hopCount = 6;
private KNXMediumSettings medium;
private final LogService logger;
// our link connection event notifier
private final EventNotifier notifier;
/**
* Creates a new network link based on the KNXnet/IP protocol, using a
* {@link KNXnetIPConnection}.
* <p>
* For more details on KNXnet/IP connections, refer to the various KNXnet/IP
* implementations.<br>
*
* @param serviceMode mode of communication to open, <code>serviceMode</code> is one
* of the service mode constants (e.g. {@link #TUNNEL}); depending on the mode
* set, the expected local / remote endpoints might differ
* @param localEP the local endpoint of the link to use;<br> - in tunneling mode
* (point-to-point), this is the client control endpoint, use <code>null</code>
* for the default local host and an ephemeral port number<br> - in
* {@link #ROUTER} mode, specifies the multicast interface, i.e. the local
* network interface is taken that has the IP address bound to it (if IP
* address is bound more than once, it's undefined which interface is
* returned), the port is not used; use <code>null</code> for
* <code>localEP</code> or an unresolved IP address to take the host's
* default multicast interface
* @param remoteEP the remote endpoint of the link to communicate with;<br> - in
* tunneling mode (point-to-point), this is the server control endpoint <br> -
* in {@link #ROUTER} mode, the IP address specifies the multicast group to
* join, the port is not used; use <code>null</code> for
* <code>remoteEP</code> or an unresolved IP address to take the default
* multicast group
* @param useNAT <code>true</code> to use network address translation in tunneling
* service mode, <code>false</code> to use the default (non aware) mode;
* parameter is ignored for routing
* @param settings medium settings defining device and medium specifics needed for
* communication
* @throws KNXException on failure establishing link using the KNXnet/IP connection
*/
public KNXNetworkLinkIP(int serviceMode, InetSocketAddress localEP,
InetSocketAddress remoteEP, boolean useNAT, KNXMediumSettings settings)
throws KNXException
{
switch (serviceMode) {
case TUNNEL:
InetSocketAddress local = localEP;
if (local == null)
try {
local = new InetSocketAddress(InetAddress.getLocalHost(), 0);
}
catch (final UnknownHostException e) {
throw new KNXException("no local host available");
}
conn = new KNXnetIPTunnel(KNXnetIPTunnel.LINK_LAYER, local, remoteEP, useNAT);
break;
case ROUTER:
NetworkInterface netIf = null;
if (localEP != null && !localEP.isUnresolved())
try {
netIf = NetworkInterface.getByInetAddress(localEP.getAddress());
}
catch (final SocketException e) {
throw new KNXException("error getting network interface: "
+ e.getMessage());
}
final InetAddress mcast = remoteEP != null ? remoteEP.getAddress() : null;
conn = new KNXnetIPRouter(netIf, mcast);
break;
default:
throw new KNXIllegalArgumentException("unknown service mode");
}
// initialize our link with opened connection
mode = serviceMode;
logger = LogManager.getManager().getLogService(getName());
notifier = new LinkNotifier(this, logger);
conn.addConnectionListener(notifier);
// configure KNX medium stuff
setKNXMedium(settings);
}
/**
* Creates a new network link based on the KNXnet/IP tunneling protocol, using a
* {@link KNXnetIPTunnel} with default communication settings.
* <p>
* The link is established using a KNXnet/IP tunnel, the local endpoint is the default
* local host, the remote endpoint uses the default KNXnet/IP port number, network
* address translation (NAT) is disabled.
*
* @param remoteHost remote host name
* @param settings medium settings defining device and medium specifics needed for
* communication
* @throws KNXException on failure establishing link using the KNXnet/IP connection
*/
public KNXNetworkLinkIP(String remoteHost, KNXMediumSettings settings)
throws KNXException
{
this(TUNNEL, null, new InetSocketAddress(remoteHost, KNXnetIPConnection.IP_PORT),
false, settings);
}
/**
* Creates a new network link based on the KNXnet/IP routing protocol, using a
* {@link KNXnetIPRouter}.
* <p>
*
* @param netIf local network interface used to join the multicast group and for
* sending, use <code>null</code> for the host's default multicast interface
* @param mcGroup address of the multicast group to join, use <code>null</code> for
* the default KNXnet/IP multicast address
* @param settings medium settings defining device and medium specifics needed for
* communication
* @throws KNXException on failure establishing link using the KNXnet/IP connection
*/
public KNXNetworkLinkIP(NetworkInterface netIf, InetAddress mcGroup,
KNXMediumSettings settings) throws KNXException
{
conn = new KNXnetIPRouter(netIf, mcGroup);
// initialize our link
mode = ROUTER;
logger = LogManager.getManager().getLogService(getName());
notifier = new LinkNotifier(this, logger);
conn.addConnectionListener(notifier);
// configure KNX medium stuff
setKNXMedium(settings);
}
/* (non-Javadoc)
* @see tuwien.auto.calimero.link.KNXNetworkLink#setKNXMedium
* (tuwien.auto.calimero.link.medium.KNXMediumSettings)
*/
public void setKNXMedium(KNXMediumSettings settings)
{
if (settings == null)
throw new KNXIllegalArgumentException("medium settings are mandatory");
if (medium != null && !settings.getClass().isAssignableFrom(medium.getClass())
&& !medium.getClass().isAssignableFrom(settings.getClass()))
throw new KNXIllegalArgumentException("medium differs");
medium = settings;
}
/* (non-Javadoc)
* @see tuwien.auto.calimero.link.KNXNetworkLink#getKNXMedium()
*/
public KNXMediumSettings getKNXMedium()
{
return medium;
}
/* (non-Javadoc)
* @see tuwien.auto.calimero.link.KNXNetworkLink#addLinkListener
* (tuwien.auto.calimero.link.event.NetworkLinkListener)
*/
public void addLinkListener(NetworkLinkListener l)
{
notifier.addListener(l);
}
/* (non-Javadoc)
* @see tuwien.auto.calimero.link.KNXNetworkLink#removeLinkListener
* (tuwien.auto.calimero.link.event.NetworkLinkListener)
*/
public void removeLinkListener(NetworkLinkListener l)
{
notifier.removeListener(l);
}
/* (non-Javadoc)
* @see tuwien.auto.calimero.link.KNXNetworkLink#setHopCount(int)
*/
public final void setHopCount(int count)
{
if (count < 0 || count > 7)
throw new KNXIllegalArgumentException("hop count out of range [0..7]");
hopCount = (byte) count;
logger.info("hop count set to " + count);
}
/* (non-Javadoc)
* @see tuwien.auto.calimero.link.KNXNetworkLink#getHopCount()
*/
public final byte getHopCount()
{
return hopCount;
}
/**
* {@inheritDoc} When communicating with a KNX network which uses open medium,
* messages are broadcasted within domain (as opposite to system broadcast) by
* default. Specify <code>dst null</code> for system broadcast.
*/
public void sendRequest(KNXAddress dst, Priority p, byte[] nsdu)
throws KNXLinkClosedException, KNXTimeoutException
{
send(dst, p, nsdu, false);
}
/**
* {@inheritDoc} When communicating with a KNX network which uses open medium,
* messages are broadcasted within domain (as opposite to system broadcast) by
* default. Specify <code>dst null</code> for system broadcast.
*/
public void sendRequestWait(KNXAddress dst, Priority p, byte[] nsdu)
throws KNXTimeoutException, KNXLinkClosedException
{
send(dst, p, nsdu, true);
}
/* (non-Javadoc)
* @see tuwien.auto.calimero.link.KNXNetworkLink#send
* (tuwien.auto.calimero.cemi.CEMILData, boolean)
*/
public void send(CEMILData msg, boolean waitForCon) throws KNXTimeoutException,
KNXLinkClosedException
{
doSend(adjustMsgType(msg), waitForCon);
}
/* (non-Javadoc)
* @see tuwien.auto.calimero.link.KNXNetworkLink#getName()
*/
public String getName()
{
// do our own IP:port string, since InetAddress.toString() always prepends a '/'
final InetSocketAddress a = conn.getRemoteAddress();
return "link " + a.getAddress().getHostAddress() + ":" + a.getPort();
}
/* (non-Javadoc)
* @see tuwien.auto.calimero.link.KNXNetworkLink#isOpen()
*/
public boolean isOpen()
{
return !closed;
}
/* (non-Javadoc)
* @see tuwien.auto.calimero.link.KNXNetworkLink#close()
*/
public void close()
{
synchronized (this) {
if (closed)
return;
closed = true;
}
conn.close();
notifier.quit();
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString()
{
return getName() + (mode == TUNNEL ? " tunnel" : " routing") + " mode"
+ (closed ? " (closed), " : ", ") + medium.getMediumString()
+ " medium hopcount " + hopCount;
}
private CEMILData adjustMsgType(CEMILData msg)
{
final boolean srcOk = msg.getSource().getRawAddress() != 0;
// just return if we don't need to adjust source address and don't need LDataEx
if ((srcOk || medium.getDeviceAddress().getRawAddress() == 0)
&& (medium instanceof TPSettings || msg instanceof CEMILDataEx))
return msg;
return (CEMILDataEx) CEMIFactory.create(srcOk ? null : medium.getDeviceAddress(),
null, msg, true);
}
private void send(KNXAddress dst, Priority p, byte[] nsdu, boolean confirm)
throws KNXTimeoutException, KNXLinkClosedException
{
final CEMILData f;
final short mc = mode == TUNNEL ? CEMILData.MC_LDATA_REQ : CEMILData.MC_LDATA_IND;
final IndividualAddress src = medium.getDeviceAddress();
// use default address 0 in system broadcast
final KNXAddress d = dst == null ? new GroupAddress(0) : dst;
final boolean tp = medium.getMedium() == KNXMediumSettings.MEDIUM_TP0
|| medium.getMedium() == KNXMediumSettings.MEDIUM_TP1;
if (nsdu.length <= 16 && tp)
f = new CEMILData(mc, src, d, nsdu, p, true, hopCount);
else
f = new CEMILDataEx(mc, src, d, nsdu, p, true, dst != null, false, hopCount);
doSend(f, confirm);
}
private void doSend(CEMILData msg, boolean waitForCon) throws KNXTimeoutException,
KNXLinkClosedException
{
if (closed)
throw new KNXLinkClosedException("link closed");
if (medium instanceof PLSettings) {
final CEMILDataEx f = (CEMILDataEx) msg;
if (f.getAdditionalInfo(CEMILDataEx.ADDINFO_PLMEDIUM) == null) {
f.addAdditionalInfo(CEMILDataEx.ADDINFO_PLMEDIUM, ((PLSettings) medium)
.getDomainAddress());
logger.trace("send - added PL additional info to message");
}
}
else if (medium.getMedium() == KNXMediumSettings.MEDIUM_RF) {
final CEMILDataEx f = (CEMILDataEx) msg;
final RFSettings rf = (RFSettings) medium;
if (f.getAdditionalInfo(CEMILDataEx.ADDINFO_RFMEDIUM) == null) {
final byte[] sn =
f.isDomainBroadcast() ? rf.getDomainAddress() : rf.getSerialNumber();
// add-info: rf-info (0 ignores a lot), sn (6 bytes), lfn (=255:void)
f.addAdditionalInfo(CEMILDataEx.ADDINFO_RFMEDIUM, new byte[] { 0, sn[0],
sn[1], sn[2], sn[3], sn[4], sn[5], (byte) 0xff });
logger.trace("send - added RF additional info to message "
+ (f.isDomainBroadcast() ? "(domain address)" : "(s/n)"));
}
}
try {
logger.info("send message to " + msg.getDestination()
+ (waitForCon ? ", wait for confirmation" : ""));
logger.trace("cEMI " + msg);
conn.send(msg, waitForCon ? KNXnetIPConnection.WAIT_FOR_CON
: KNXnetIPConnection.WAIT_FOR_ACK);
logger.trace("send to " + msg.getDestination() + " succeeded");
}
catch (final KNXConnectionClosedException e) {
logger.error("send error, closing link", e);
close();
throw new KNXLinkClosedException("link closed, " + e.getMessage());
}
}
}
我已经使用调试器检查了赋予方法的值:
isaLocalEP = /169.254.96.102:12345
isaRemoteEP = /169.254.96.33:3671
所以它们不为空。
有什么想法吗?也许 IPv4 或 IPv6 存在一些问题?
LogCat 使用 getAddress().getHostAddress()
11-07 10:04:12.800: W/System.err(14989): tuwien.auto.calimero.exception.KNXException: bind failed: EADDRINUSE (Address already in use)
11-07 10:04:12.805: W/System.err(14989): at tuwien.auto.calimero.knxnetip.ConnectionImpl.connect(ConnectionImpl.java:369)
11-07 10:04:12.805: W/System.err(14989): at tuwien.auto.calimero.knxnetip.KNXnetIPTunnel.<init>(KNXnetIPTunnel.java:117)
11-07 10:04:12.805: W/System.err(14989): at tuwien.auto.calimero.link.KNXNetworkLinkIP.<init>(KNXNetworkLinkIP.java:179)
11-07 10:04:12.805: W/System.err(14989): at com.example.connectiontest.KNXNetwork.connect(KNXNetwork.java:149)
11-07 10:04:12.805: W/System.err(14989): at com.example.connectiontest.KNXNetwork.connect(KNXNetwork.java:122)
11-07 10:04:12.805: W/System.err(14989): at com.example.connectiontest.KNXNetwork.tryConnecting(KNXNetwork.java:80)
11-07 10:04:12.805: W/System.err(14989): at com.example.connectiontest.HelloKNXNetwork.connect(HelloKNXNetwork.java:67)
11-07 10:04:12.805: W/System.err(14989): at com.example.connectiontest.HelloKNXNetwork.onClickActivity(HelloKNXNetwork.java:42)
11-07 10:04:12.805: W/System.err(14989): at java.lang.reflect.Method.invokeNative(Native Method)
11-07 10:04:12.805: W/System.err(14989): at java.lang.reflect.Method.invoke(Method.java:511)
11-07 10:04:12.805: W/System.err(14989): at android.view.View$1.onClick(View.java:3111)
11-07 10:04:12.805: W/System.err(14989): at android.view.View.performClick(View.java:3644)
11-07 10:04:12.805: W/System.err(14989): at android.view.View$PerformClick.run(View.java:14313)
11-07 10:04:12.805: W/System.err(14989): at android.os.Handler.handleCallback(Handler.java:605)
11-07 10:04:12.805: W/System.err(14989): at android.os.Handler.dispatchMessage(Handler.java:92)
11-07 10:04:12.805: W/System.err(14989): at android.os.Looper.loop(Looper.java:137)
11-07 10:04:12.805: W/System.err(14989): at android.app.ActivityThread.main(ActivityThread.java:4514)
11-07 10:04:12.805: W/System.err(14989): at java.lang.reflect.Method.invokeNative(Native Method)
11-07 10:04:12.810: W/System.err(14989): at java.lang.reflect.Method.invoke(Method.java:511)
11-07 10:04:12.810: W/System.err(14989): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
11-07 10:04:12.810: W/System.err(14989): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
11-07 10:04:12.810: W/System.err(14989): at dalvik.system.NativeStart.main(Native Method)
LogCat 使用端口 0
11-07 10:16:32.085: W/System.err(17185): android.os.NetworkOnMainThreadException
11-07 10:16:32.090: W/System.err(17185): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
11-07 10:16:32.090: W/System.err(17185): at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:175)
11-07 10:16:32.090: W/System.err(17185): at libcore.io.IoBridge.sendto(IoBridge.java:463)
11-07 10:16:32.090: W/System.err(17185): at java.net.PlainDatagramSocketImpl.send(PlainDatagramSocketImpl.java:182)
11-07 10:16:32.090: W/System.err(17185): at java.net.DatagramSocket.send(DatagramSocket.java:287)
11-07 10:16:32.090: W/System.err(17185): at tuwien.auto.calimero.knxnetip.ConnectionImpl.connect(ConnectionImpl.java:360)
11-07 10:16:32.090: W/System.err(17185): at tuwien.auto.calimero.knxnetip.KNXnetIPTunnel.<init>(KNXnetIPTunnel.java:117)
11-07 10:16:32.090: W/System.err(17185): at tuwien.auto.calimero.link.KNXNetworkLinkIP.<init>(KNXNetworkLinkIP.java:179)
11-07 10:16:32.090: W/System.err(17185): at com.example.connectiontest.KNXNetwork.connect(KNXNetwork.java:148)
11-07 10:16:32.090: W/System.err(17185): at com.example.connectiontest.KNXNetwork.connect(KNXNetwork.java:121)
11-07 10:16:32.090: W/System.err(17185): at com.example.connectiontest.KNXNetwork.tryConnecting(KNXNetwork.java:79)
11-07 10:16:32.090: W/System.err(17185): at com.example.connectiontest.HelloKNXNetwork.connect(HelloKNXNetwork.java:67)
11-07 10:16:32.090: W/System.err(17185): at com.example.connectiontest.HelloKNXNetwork.onClickActivity(HelloKNXNetwork.java:42)
11-07 10:16:32.090: W/System.err(17185): at java.lang.reflect.Method.invokeNative(Native Method)
11-07 10:16:32.090: W/System.err(17185): at java.lang.reflect.Method.invoke(Method.java:511)
11-07 10:16:32.095: W/System.err(17185): at android.view.View$1.onClick(View.java:3111)
11-07 10:16:32.095: W/System.err(17185): at android.view.View.performClick(View.java:3644)
11-07 10:16:32.095: W/System.err(17185): at android.view.View$PerformClick.run(View.java:14313)
11-07 10:16:32.095: W/System.err(17185): at android.os.Handler.handleCallback(Handler.java:605)
11-07 10:16:32.095: W/System.err(17185): at android.os.Handler.dispatchMessage(Handler.java:92)
11-07 10:16:32.095: W/System.err(17185): at android.os.Looper.loop(Looper.java:137)
11-07 10:16:32.095: W/System.err(17185): at android.app.ActivityThread.main(ActivityThread.java:4514)
11-07 10:16:32.095: W/System.err(17185): at java.lang.reflect.Method.invokeNative(Native Method)
11-07 10:16:32.095: W/System.err(17185): at java.lang.reflect.Method.invoke(Method.java:511)
11-07 10:16:32.095: W/System.err(17185): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
11-07 10:16:32.095: W/System.err(17185): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
11-07 10:16:32.095: W/System.err(17185): at dalvik.system.NativeStart.main(Native Method)
最佳答案
我认为问题在于您有 IP 地址,但没有主机名!试试这个:
System.out.println(isaLocalEP.getAddress().getHostAddress() + ":" + isaLocalEP.getPort());
关于Java/Android : getHostName() is always null with InetSocketAddress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13265332/
有没有办法将字符串参数传递给 InetSocketAddress 的参数? 这是生成代理的正确方法: SocketAddress addr = new InetSocketAddress("127.0
我正在尝试填充主机 header 。我已经为我的示例插入了虚拟数据,但我想知道我是否正确填充了该数据。当检查地址的值时,它似乎与我的预期不同。我期望 [域名]:[端口],但我看到 [域名]/[IP 地
我有以下代码: socket.connect(new InetSocketAddress(serverHost, serverPort), CONNECT_TIMEOUT); 问题是当 DNS 不可访
在构造函数的文档中 InetSocketAddress(int port)它说: Creates a socket address where the IP address is the wildca
谁能解释一下 InetAddress 之间有什么区别吗?和 InetSocketAddress java中的类,如果有差异,请解释相同。我用谷歌搜索了它,但找不到任何解释。 最佳答案 InetAddr
我在与主机名中带有重音符号 (é è ô...) 的服务器建立连接时遇到问题。 例如: String oUrl = "www.hôtel.fr"; System.out.println(oUrl)
我需要为 InetSocketAddress 编写 Comparator,这样我就可以在 TreeSet 中使用此类。它们需要通过地址和端口进行比较。 代码看起来像这样,但问题是我不知道如何通过 (1
为什么我们必须创建一个InetSocketAddress对象? 但是对于ServerSocket,我们只需使用int来输入端口号 示例: try( ServerSocketChanne
我进行了很多搜索,但无法找到两者之间的直接区别。在创建客户端套接字时,我们什么时候使用每一个? 最佳答案 InetSocketAddress 不以任何方式管理 Socket。 我认为你的意思是 Soc
我正在 InetSocketAddress 上执行 .toString()。这是 Android websocket 客户端的一部分,迄今为止无法连接到主机。 现在变量 address.toStrin
首先:我对 Spring 非常陌生,因此,如果我未能提供该问题所需的所有信息,我很抱歉。我的问题如下:我有以下类,我想将哪些对象保存在 mongoDB 中 public class Subscript
这是我尝试过的: @Test public void local_host_test() { InetAddress inetAddress = Mockito.mock(InetAddres
我正在使用一个使用开源 java 库 (Calimero) 的 Android 应用程序。我的代码尝试使用以下代码获取主机名和端口: private static KNXNetworkLinkIP c
我想要实现的目标 将服务器绑定(bind)到临时端口以进行单元测试。 我的问题: 使用 1.5.0_22 JDK,我尝试按照 javadoc 使用端口 0 将 InetSocketAddress 绑定
我想创建一个 InetSocketAddress,但无论我得到的是 host:port 还是 ip:port,我都想正确地创建它。我看到它有两个构造函数,一个用于主机 (String),另一个用于 I
当我启动通过elasticsearch java api 与ElasticSearch 5.6.10 交互的java 应用程序并且我的elasticsearch 集群有超过1 个节点时,我收到以下异常
我正在寻找 ipv4 和 ipv6 的测试正则表达式 InetSocketAddress (即 IP 地址 + 端口号)。我对验证主机名不感兴趣。 它可以是两个正则表达式(一个用于 ipv4,一个用于
我正在尝试以字符串形式获取套接字连接的 IP。 我正在使用一个框架,它返回接收到的消息的 SocketAddress。我如何将其转换为 InetSocketAddress 或 InetAddress?
我需要有效地确定 InetSocketAddress 是 IPv6 还是 IPv4。我能看到的唯一两种方法是使用 instanceof 运算符,或者检查 getAddress() 的长度(应该返回一个
Java 中验证 host:port 形式的字符串并将其转换为 InetSocketAddress 实例的常用方法是什么? 如果满足以下条件就好了: 没有地址查找; 适用于 IPv4、IPv6 和“字
我是一名优秀的程序员,十分优秀!