FileDocCategorySizeDatePackage
MagnetURIHandlerClient.javaAPI DocAzureus 3.0.3.42693Tue Dec 26 18:20:48 GMT 2006com.aelitis.net.magneturi.impl

MagnetURIHandlerClient

public class MagnetURIHandlerClient extends Object

Fields Summary
protected static final String
NL
Constructors Summary
Methods Summary
public booleanload(java.lang.String magnet_uri, int max_millis_to_wait)


	 
	
			
				 
	
			// limit the subset here as we're looping waiting for something to be alive and we can't afford to take ages getting back to the start
		
		long	start = System.currentTimeMillis();
		
		while( true ){
			
			for (int i=45100;i<=45108;i++){
	
				long	now = System.currentTimeMillis();
				
				if ( now < start ){
					
					start  = now;
				}
				
				if ( now - start > max_millis_to_wait ){
					
					return( false );
				}
				
				Socket	sock = null;
				
				try{
					sock = new Socket();
					
					System.out.println( "trying " + i );
					
					sock.connect( new InetSocketAddress( "127.0.0.1", i ), 500 );
					
					sock.setSoTimeout( 5000 );
					
					PrintWriter	pw = new PrintWriter( sock.getOutputStream());
					
					pw.println( "GET /select/" + magnet_uri + NL + NL );
					
					pw.flush();
					
					InputStream	is = sock.getInputStream();
					
					String	res = "";
					
					byte[]	buffer = new byte[1024];
	
					while( true ){
						
						int	len = is.read( buffer );
						
						if ( len <= 0 ){
							
							break;
						}
						
						res += new String( buffer, 0, len );
						
						if ( res.indexOf( " 200" ) != -1 ){
							
							return( true );
						}
					}
				}catch( Throwable e ){
					
				}finally{
					
					if ( sock != null ){

						try{
							sock.close();
							
						}catch( Throwable e ){
						}
					}
				}
			}
		}
	
public static voidmain(java.lang.String[] args)

		new MagnetURIHandlerClient().load( "jkjjk", 30000 );