(int port)
| 698 | } |
| 699 | |
| 700 | public static boolean isPortAvailable(int port){ |
| 701 | boolean available = true; |
| 702 | |
| 703 | int available_code = mOpenPorts.get(port); |
| 704 | |
| 705 | if(available_code != 0) |
| 706 | return available_code != 1; |
| 707 | |
| 708 | try{ |
| 709 | // attempt 3 times since proxy and server could be still releasing |
| 710 | // their ports |
| 711 | for(int i = 0; i < 3; i++){ |
| 712 | Socket channel = new Socket(); |
| 713 | InetSocketAddress address = new InetSocketAddress(InetAddress.getByName(mNetwork.getLocalAddressAsString()), port); |
| 714 | |
| 715 | channel.connect(address, 200); |
| 716 | |
| 717 | available = !channel.isConnected(); |
| 718 | |
| 719 | channel.close(); |
| 720 | |
| 721 | if(available) |
| 722 | break; |
| 723 | |
| 724 | Thread.sleep(200); |
| 725 | } |
| 726 | } |
| 727 | catch(Exception e){ |
| 728 | available = true; |
| 729 | } |
| 730 | |
| 731 | mOpenPorts.put(port, available ? 2 : 1); |
| 732 | |
| 733 | return available; |
| 734 | } |
| 735 | |
| 736 | public static ArrayList<String> getAvailableSessionFiles(){ |
| 737 | ArrayList<String> files = new ArrayList<String>(); |
no test coverage detected