| | |
| | | |
| | | // final SocketOptions options = new SocketOptions(); |
| | | // |
| | | MessagePipeLine pipeLine = new MessagePipeLine(); |
| | | // MessagePipeLine pipeLine = new MessagePipeLine(); |
| | | // options.setHandleMessage(pipeLine); |
| | | // options.setEnabledHeartbeat(false); |
| | | |
| | |
| | | @Override |
| | | public void onMessage(Object msg) { |
| | | LinkResponse response = (LinkResponse)msg; |
| | | if(response != null){ |
| | | Log.i(TAG, "AllTopicsListener" |
| | | + "\nTopic: " + response.getTopic() |
| | | +"\n Data: " + response.getData()); |
| | | handleLinkResponse(response); |
| | | } |
| | | |
| | | } |
| | | }; |
| | | HDLLink.getInstance().registerAllTopicsListener(allTopicsListener); |
| | |
| | | return "255.255.255.255";
|
| | | }
|
| | |
|
| | | public static boolean isLocalIpAddress(String ipAddress) {
|
| | | try {
|
| | | for (Enumeration<NetworkInterface> niEnum = NetworkInterface.getNetworkInterfaces();
|
| | | niEnum.hasMoreElements(); ) {
|
| | | NetworkInterface ni = niEnum.nextElement();
|
| | | for (InterfaceAddress interfaceAddress : ni.getInterfaceAddresses()) {
|
| | | if (ipAddress.equals(interfaceAddress.getAddress().getHostAddress())) {
|
| | | return true;
|
| | | }
|
| | | }
|
| | | }
|
| | | } catch (SocketException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | public static String getIP(Context application) {
|
| | | WifiManager wifiManager = (WifiManager) application.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
| | | if (!wifiManager.isWifiEnabled()) {
|
| | |
| | | } else {
|
| | | response.setData(new String(body, "utf-8"));
|
| | | }
|
| | | LogUtils.i("LinkMessageDecoder", "LinkMessageDecoder->decoder:" + response.getTopic() + "\r\n" + response.getData());
|
| | | LogUtils.i( "LinkMessageDecoder->decoder:" + response.getTopic() + "\r\n" + response.getData());
|
| | | //解析完成,topic发送一次
|
| | | EventDispatcher.getInstance().post(response.getTopic(), response);
|
| | | }
|
| | |
| | | if (msg instanceof LinkResponse) { |
| | | LinkResponse linkResponse = (LinkResponse) msg; |
| | | String data = linkResponse.getData(); |
| | | LogUtils.i("搜索到网关->" + data); |
| | | if (!TextUtils.isEmpty(data)) { |
| | | final BaseLocalResponse<GatewaySearchBean> response = GsonConvert.getGson().fromJson(data, new TypeToken<BaseLocalResponse<GatewaySearchBean>>() { |
| | | }.getType()); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | |
| | |
| | | import java.net.DatagramSocket;
|
| | | import java.net.InetAddress;
|
| | | import java.net.InetSocketAddress;
|
| | | import java.net.SocketAddress;
|
| | | import java.util.List;
|
| | | import java.util.concurrent.atomic.AtomicBoolean;
|
| | |
|
| | |
| | | }
|
| | | //排除自己发出去的
|
| | | try {
|
| | | if (receivePacket.getAddress().getHostAddress()
|
| | | .equals(IpUtils.getIP(HDLSdk.getInstance().getContext()))) {
|
| | | if (IpUtils.isLocalIpAddress( receivePacket.getAddress().getHostAddress()))
|
| | | return;
|
| | | }
|
| | | } catch (Exception ignored) {
|
| | |
|
| | | }
|