Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  UxNetIO - new lightweight scalable network lib  (Read 1422 times)
0 Members and 1 Guest are viewing this topic.
Offline Dxu1994
« Posted 2013-12-28 18:02:29 »

Hey everyone, just wanted to release my networking library as used in my MMO as open source. I know there's many of these out there like KyroNet but I found this much easier to use (and maybe others will too?)

Link: https://github.com/Davidx1337/UxNetIO

License: MIT (do whatever you want basically)

It is based on the Apache MINA API (design wise) but i've removed many layers of abstraction that MINA provides as well as providing a backwards-compatible API for old raw java.net.Socket usage. This boils down to a 12kb jar file while MINA is over 300kb!

Example HTTP server (very basic):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
public static void main(String[] argv)
            throws Throwable {
        SocketAcceptor acceptor = new SocketAcceptor(80, 10);
        acceptor.bind(new Protocol() {
            ProtocolEncoder encoder = new ProtocolEncoder() {
                public void dispose() {

                }

                public void encode(IoSession session, Object message, EncoderOutput output) {
                    String str = (String) message;
                    str = "<div style=\"color:blue;\">" + str;
                    str += "</div>\n";
                    ByteBuffer bb = ByteBuffer.allocate(str.length());
                    bb.put(str.getBytes());
                    bb.flip();
                    output.write(bb);
                }
            };
            ProtocolDecoder decoder = new ProtocolDecoder() {
                public void dispose() {

                }

                public void decode(IoSession session, ByteBuffer message, DecoderOutput output) {
                    byte[] data = message.array();
                    output.write(new String(data));
                }
            };

            public ProtocolEncoder getEncoder() {
                return encoder;
            }

            public ProtocolDecoder getDecoder() {
                return decoder;
            }
        }, new IoListener() {

            public void onSessionCreated(IoSession session) {
                System.err.println("SessionCreated");
            }

            public void onSessionOpened(IoSession session) {
                System.err.println("SessionOpened");
            }

            public void onMessageSent(IoSession session, Object message) {
                System.err.println("MessageSent: " + message);
            }

            public void onMessageReceived(IoSession session, Object message) {
                System.err.println("MessageReceived: " + message);
                for (int i = 0; i < 100; i++) {
                    StringBuilder b = new StringBuilder("Hello from UxNetIO! This is line:"+i);
                    session.write(b.toString());
                }
                session.close();
            }

            public void onSessionClosed(IoSession session) {
                System.err.println("SessionClosed");
            }

            public void onExceptionOccurred(IoSession session, Throwable ex) {
                ex.printStackTrace();
            }
        });
       
        System.err.println("LISTENING ON PORT: " + acceptor.getPort());
    }


Output: (Google Chrome)



One of the games utilising this library is my MMORPG Renoria (it worked for us so maybe it will work for someone else?):



Either way, I hope someone finds this useful!

Offline CommanderKeith
« Reply #1 - Posted 2013-12-30 03:23:33 »

Cool, thanks for sharing, good idea to simplify MINA. I did a similar thing a few years ago when I tried to make a networked game. MINA is very good but it takes so much learning and implementation of wrapper classes just to figure out how to send a byte array!

Nowadays there's KryoNet which is used in many games and Riven's NIO library which I think is used in minecraft which are obviously also very good alternatives as you point out.

Offline Dxu1994
« Reply #2 - Posted 2013-12-30 16:28:18 »

Cool, thanks for sharing, good idea to simplify MINA. I did a similar thing a few years ago when I tried to make a networked game. MINA is very good but it takes so much learning and implementation of wrapper classes just to figure out how to send a byte array!

Nowadays there's KryoNet which is used in many games and Riven's NIO library which I think is used in minecraft which are obviously also very good alternatives as you point out.

Thanks, yeah, initially my server and client were both running off MINA but I decided MINA is a bit too generic and I wanted a library specifically suited for high performance network gaming, but still with an API structure similar to MINA. Hence this was born.

KyroNet is a good library, but it has its uses and I don't believe it's that great when used in a MMORPG server, but each to their own Smiley

This also has old Socket fallback when you aren't able to instantiate a Selector (for example sometimes when running from an Applet)

I'll release some more demos and examples later for this (with binary serialization and stuff), I guess I just decided Ive used a lot of libraries from the community like LWJGL, LibGDX and stuff and decided to contribute something back.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Dxu1994
« Reply #3 - Posted 2013-12-31 22:14:04 »

Little update - Fixed some compilation errors some people were getting, and made the PacketWriter class work directly with a byte array instead of using BYteArrayOutputStream, speed increases of over 20x have been reported with the server JVM.

Offline gouessej
« Reply #4 - Posted 2014-01-03 10:25:47 »

KyroNet is a good library, but it has its uses and I don't believe it's that great when used in a MMORPG server, but each to their own Smiley
Please can you elaborate?

Offline Dxu1994
« Reply #5 - Posted 2014-01-04 23:17:46 »

KyroNet is a good library, but it has its uses and I don't believe it's that great when used in a MMORPG server, but each to their own Smiley
Please can you elaborate?

I believe KyroNet is single threaded, even on the server. This library allows you to pass in an Executor into the constructor and thread limit. Better for throughput vital systems which are able to take advantage of multi cores, like MMORPG servers.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (44 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (62 views)
2014-09-21 02:42:18

BurntPizza (32 views)
2014-09-21 01:30:30

moogie (39 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!