Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Mina networking

  1. #1
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Mina networking

    My server, that I'm using, runs off Mina networking, and is pretty inefficient when accepting connections. How would I improve the networking?

    How could I improve this?

    Here's the main void.
     
    	@Override
    	public void run() {
    		/**
    		 * Starting Up Server
    		 */
    		System.setOut(new Logger1(System.out));
    		System.setErr(new Logger1(System.err));
    		log.log(Level.INFO, "Launching Deathzscape the Project Insanity base");
     
    		/**
    		 * Accepting Connections
    		 */
    		acceptor = new SocketAcceptor();
    		connectionHandler = new ConnectionHandler();
     
    		SocketAcceptorConfig sac = new SocketAcceptorConfig();
    		sac.getSessionConfig().setTcpNoDelay(false);
    		sac.setReuseAddress(true);
    		sac.setBacklog(100);
     
    		throttleFilter = new ConnectionThrottleFilter(Config.CONNECTION_DELAY);
    		sac.getFilterChain().addFirst("throttleFilter", throttleFilter);
    		try {
    			acceptor.bind(new InetSocketAddress(serverlistenerPort),
    					connectionHandler, sac);
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		/**
    		 * Server Successfully Loaded
    		 */
    		log.log(Level.INFO, "Server listening on port 0.0.0.0:"
    				+ serverlistenerPort);
    		/**
    		 * Main Server Tick
    		 */
    		try {
    			do {
                                 //process code was here
    			} while (!Server.shutdownServer);
    		} catch (Exception ex) {
    			ex.printStackTrace();
    			log.log(Level.SEVERE, "A fatal exception has been thrown!");
    		}
    		acceptor = null;
    		connectionHandler = null;
    		sac = null;
    		System.exit(0);
    	}


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Mina networking

    Pass the socket to a new instance of the handler and loop.

  3. #3
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Mina networking

    Quote Originally Posted by Norm View Post
    Pass the socket to a new instance of the handler and loop.
    Wait what?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Mina networking

    Something like this using Java SE classes and methods: An infinite loop that gets a connection/socket, creates a new object to handle that socket and then loops back to await the next connection

    while(true) { 
       socket = serverSocket.accept();  // Get a socket
       new TheConnectionHandler(socket);  // pass the reference to the socket to an object to handle the communications
    } // end loop go back to the accept() method to wait for the next connection
    Last edited by Norm; December 24th, 2011 at 01:00 PM.

  5. #5
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Mina networking

    Quote Originally Posted by Norm View Post
    Something like this: An infinite loop that gets a connection/socket, creates a new object to handle that socket and then loops back to await the next connection

    while(true) { 
       acceptor = new SocketAcceptor();  // Get a socket
       new ConnectionHandler(acceptor);  // pass the reference to the socket to handle the communications
    } // end loop go back to the accept() method to wait for the next connection
    but then it won't execute the process?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Mina networking

    I changed my post slightly. Take another look. I am using Java SE classes and methods.

Similar Threads

  1. Networking Java
    By aneel in forum JDBC and Database Tutorials
    Replies: 1
    Last Post: December 13th, 2011, 03:28 AM
  2. Game Networking
    By Parsnips in forum Java Networking
    Replies: 15
    Last Post: December 1st, 2011, 02:57 PM
  3. networking in java
    By sridhar in forum Member Introductions
    Replies: 1
    Last Post: October 4th, 2010, 11:11 AM
  4. networking problem
    By anurupr in forum Java Networking
    Replies: 0
    Last Post: March 15th, 2010, 04:26 AM
  5. [SOLVED] java networking
    By renu1 in forum Java Networking
    Replies: 0
    Last Post: March 12th, 2010, 12:33 PM