RTMP 端口工作与否检查 android

RTMP port working or not check android

我开发了一个应用opentok.They使用的是RMTP,443port.I想检查这个端口是否在android中打开wifi连接network.How可以我检查 that.Any 帮助将不胜感激

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);
}
}