0
我開發了一個opentok使用的應用程序,他們使用的是RMTP,443端口。我想檢查一下這個端口是否在android wifi連接的網絡中打開。我該如何檢查.Any幫助將不勝感激RTMP端口工作或不檢查android
我開發了一個opentok使用的應用程序,他們使用的是RMTP,443端口。我想檢查一下這個端口是否在android wifi連接的網絡中打開。我該如何檢查.Any幫助將不勝感激RTMP端口工作或不檢查android
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);
}
}