【问题标题】:RTMP port working or not check androidRTMP端口工作与否检查android
【发布时间】:2015-07-03 05:22:40
【问题描述】:

我开发了一个由 opentok 使用的应用程序。他们使用的是 RMTP,443 端口。我想检查这个端口是否在 android wifi 连接的网络中打开。我该如何检查。任何帮助将不胜感激

【问题讨论】:

    标签: android wifi port protocols


    【解决方案1】:
    private static class MyTask extends AsyncTask < Void, Void, Void > {
    private Context mContext;
    Boolean block = false;
    MyTask(Context context) {
        if (context == null) {
            throw new IllegalArgumentException("Context can't be null");
        }
        mContext = context;
    }@Override
    
    protected Void doInBackground(Void...params) {
        Socket socket = null;
    try {
    
    InetAddress address = InetAddress.getByName(Constants.SERVER_PORT_CHECK);//give your host address here "www.example.com"
            String host = address.getHostAddress();
            socket = new Socket(host, 443);
            socket.setSoTimeout(5000);
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            block = true;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            block = true;
        } finally {
            if (socket != null) {
    
                try {
                    socket.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
    
    @Override
    protected void onPostExecute(Void aVoid) {
        if (block) {
            final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ContactWithOperator.opref);
            alertDialogBuilder.setIcon(android.R.drawable.ic_dialog_alert);
            alertDialogBuilder.setTitle(R.string.Port_block_title);
            alertDialogBuilder.setMessage(R.string.Port_block_msg);
            alertDialogBuilder.setNeutralButton("Ok", new DialogInterface.OnClickListener() {@Override
                public void onClick(DialogInterface dialog, int which) {
    
                }
            });
            alertDialogBuilder.show();
    
            //do your action here
        }
        super.onPostExecute(aVoid);
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-07
      • 2011-12-27
      • 2012-08-03
      • 2011-12-14
      • 2019-05-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多