Thread: [NIO]: Server class using the nio package

Page 1 of 3 123 LastLast
Results 1 to 10 of 25
  1. #1 [NIO]: Server class using the nio package 
    brb ridin da storm

    blakeman8192's Avatar
    Join Date
    Dec 2012
    Age
    30
    Posts
    2,012
    Thanks given
    818
    Thanks received
    1,360
    Rep Power
    330
    I won't go into detail on how nio works because its hopeless to try to explain it to noobs and I don't want posts on here saying "IM CONFUSED"

    Just know this is how Jagex does it, and this class is the most efficient server class you'll see for a while.
    Note: this will not work with your server without extensive programming, however, if implemented correctly, your server will be able to handle 2,000+ connections.

    Code:
    import java.nio.*;
    import java.nio.channels.*;
    import java.nio.charset.*;
    import java.util.*;
    
    public class Server {
    
    	public static void main(String[] args) {
    	
    		try {
    		
    			ServerSocketChannel server = ServerSocketChannel.open();
    			server.configureBlocking(false);
    			server.socket().bind(new java.net.InetSocketAddress("localhost",43594));
    			System.out.println("Server running on port 43594");
    			Selector selector = Selector.open();
    			server.register(selector,SelectionKey.OP_ACCEPT);
    			
    			for(;;) {
    			// Waiting for events from selector
    				selector.select();
    				// Getting keys
    				Set keys = selector.selectedKeys();
    				Iterator i = keys.iterator();
    
    				// For every key
    				while(i.hasNext()) {
    					SelectionKey key = (SelectionKey) i.next();
    					i.remove();
    					
    					if (key.isAcceptable()) {
    						SocketChannel client = server.accept();
    						client.configureBlocking(false);
    						client.register(selector, SelectionKey.OP_READ);
    						//Create player here
    						continue;
    					}
    				}
    			}
    		}
    		catch(Exception e) {
    			System.out.println("Error starting server.");
    		}
    	}
    
    }
    Credits: Me for programming it, Thiefmn6092 for the idea.
    rest in peace Qemist, Izzy, Colton, TeChNo PuNk, Impulser, & bootnecklad
     

  2. #2  
    Registered Member
    ill pk ur as's Avatar
    Join Date
    Jul 2007
    Posts
    424
    Thanks given
    4
    Thanks received
    12
    Rep Power
    97
    this is ownege 1 problem how do i use it??????
     

  3. #3  
    brb ridin da storm

    blakeman8192's Avatar
    Join Date
    Dec 2012
    Age
    30
    Posts
    2,012
    Thanks given
    818
    Thanks received
    1,360
    Rep Power
    330
    You have to know how it works, look up java.nio package on google.
    rest in peace Qemist, Izzy, Colton, TeChNo PuNk, Impulser, & bootnecklad
     

  4. #4  
    Registered Member
    ill pk ur as's Avatar
    Join Date
    Jul 2007
    Posts
    424
    Thanks given
    4
    Thanks received
    12
    Rep Power
    97
    completly no idea on how to use this
     

  5. #5  
    brb ridin da storm

    blakeman8192's Avatar
    Join Date
    Dec 2012
    Age
    30
    Posts
    2,012
    Thanks given
    818
    Thanks received
    1,360
    Rep Power
    330
    Sorry.. It takes some advanced skill in Java and a will to rewrite the entire base of your server to use this.
    rest in peace Qemist, Izzy, Colton, TeChNo PuNk, Impulser, & bootnecklad
     

  6. #6  
    Fasga
    Guest
    Quote Originally Posted by The Guardian View Post
    Just know this is how Jagex does it
    I lol'd.
    Quote Originally Posted by The Guardian View Post
    and this class is the most efficient server class you'll see for a while.
    I lol'd.
    Quote Originally Posted by The Guardian View Post
    I won't go into detail on how nio works because its hopeless to try to explain it to noobs and I don't want posts on here saying "IM CONFUSED"

    Just know this is how Jagex does it, and this class is the most efficient server class you'll see for a while.
    I lol'd.

    One of the main benefits of using NIO is creating an event based system, which means you'll only have to have one thread managing the clients. Currently, servers don't take advantage of this. Second, you'd need to recode all the IO operations to take advantage of NIO, not just the accepting of clients.

    Nice try, but no.
     

  7. #7  
    brb ridin da storm

    blakeman8192's Avatar
    Join Date
    Dec 2012
    Age
    30
    Posts
    2,012
    Thanks given
    818
    Thanks received
    1,360
    Rep Power
    330
    Nice try, but no.
    I lol'd

    Second, you'd need to recode all the IO operations to take advantage of NIO, not just the accepting of clients.
    I lol'd.
    Good job pointing out the obvious.


    This is just a server class, and its the beginning.
    I know that we'll have to iterate through players instead of using threads for each player.
    This is a server class using nio, not a server.

    This is just a beginning.
    Nice try, but no.


    Also, you have a horrible sense of humor.
    rest in peace Qemist, Izzy, Colton, TeChNo PuNk, Impulser, & bootnecklad
     

  8. #8  
    TORSYNK!
    Guest
    Quote Originally Posted by The Guardian View Post
    I lol'd


    I lol'd.
    Good job pointing out the obvious.


    This is just a server class, and its the beginning.
    I know that we'll have to iterate through players instead of using threads for each player.
    This is a server class using nio, not a server.

    This is just a beginning.
    Nice try, but no.


    Also, you have a horrible sense of humor.
    And you have a horrible way of programming, GTFO.
     

  9. #9  
    Registered Member
    fabjan's Avatar
    Join Date
    Jul 2007
    Age
    29
    Posts
    552
    Thanks given
    0
    Thanks received
    0
    Rep Power
    101
    Quote Originally Posted by Torsynk View Post
    And you have a horrible way of programming, GTFO.
    His way is awsome, I stick with the IO threads cuz my main sever is too large ad im too lazy to convert all threads.. buti managed to implement this into yorick's clean source
    rewrote stream and cryption
    modified he rest and dem man.. it does lagg more with low amount of ppl, but with 200+ ppl (tested with ddoser) the lagg stays te same as wit 2 ppl
    its awsome and yet so easy
    yra genius guardian.. you shouldn't release this actually, cuz every servr willsoon be good, just like 50% of the servers was dodian based like a week after the outcome of uber..

    and as normally i talk to muc lelele

    ~Fabjan
    Please vote:

    btb.servegame.com:
     

  10. #10  
    Fasga
    Guest
    Quote Originally Posted by fabjan View Post
    His way is awsome, I stick with the IO threads cuz my main sever is too large ad im too lazy to convert all threads.. buti managed to implement this into yorick's clean source
    rewrote stream and cryption
    modified he rest and dem man.. it does lagg more with low amount of ppl, but with 200+ ppl (tested with ddoser) the lagg stays te same as wit 2 ppl
    its awsome and yet so easy
    yra genius guardian.. you shouldn't release this actually, cuz every servr willsoon be good, just like 50% of the servers was dodian based like a week after the outcome of uber..

    and as normally i talk to muc lelele

    ~Fabjan
    This pulls in about #5 as far as retarded Rune-Server posts go. Nice job.
     

Page 1 of 3 123 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •