Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (777)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
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  
  Simple NIO nonblocking server with source code  (Read 6215 times)
0 Members and 1 Guest are viewing this topic.
Offline blahblahblahh

JGO Coder

Medals: 1

« Posted 2008-01-22 09:57:58 »

I've just posted:
(very simple non-blocking NIO server with fully documented source)

I needed something very simple I could use with Slick to write multiplayer games in under 16 hours each (i.e. one weekend at a time), and simple and plain enough that I could easily change it, replace it, fix it, etc.

NB: this is not intended to replace or compete with the existing full-fat java networking libraries people have written. This is the simplest possible thing I could come up with, and you'll probably find it more useful for teaching yourself NIO than for anything else. But, that said, I am actually using it in mini games including one I've already written (will post that game sometime in the coming weeks).

What does it provide?

   1. a very simple network protocol (4-byte message length followed by message)
   2. a single-threaded NIO server that copes with fragmented packets properly (took a lot of testing, but I *think* it works in all cases now)
   3. a simple Charset-based decoder to convert all messages into bytes and vice versa
   4. two abstract methods on the server that allow you to a) receive any incoming messages and b) perform "server-side game tick stuff" after each
   5. a tiny client that connects with NIO and implements the protocol

Simple stuff that most people have written for themselves by now.

I thought this might be a good tutorial for people who want to know the simplest possible example of getting NIO to send and receive strings ! (and ... at 500+ lines just to achieve that, I think I've underlined quite how low-loevel NIO really is!)

Fairly detailed javadoc here:

NB: it's not very *good*, but I was experimenting with following the rules of Scrum correctly (i.e. make it work "just good enough" in the absolute minimum possible amount of coding time).

There is one known bug that you are unlikely to encounter, which is documented with a FIXME, and requires copy/pasting some source from the server's message parser into the client's message-parser, but other than that it seems to work well enough - I've done a multiplayer tetris clone that worked fine with it.

Some time in the future, after I've used it a bit more in quick-n-dirty personal projects, I'll release an update. Or sooner, if anyone sends me fixes.

malloc will be first against the wall when the revolution comes...
Offline CommanderKeith
« Reply #1 - Posted 2008-01-22 10:09:19 »

Hi Adam,

Happy new year!

Sounds cool, I would have loved to use this.  Right now I'm looking for something with UDP as well though so I'm looking at MINA.

Something bare-bones that just sends byte arrays is definitely needed and will be used - I struggled for ages to find a mediocre implementation. For some reason most frameworks (including MINA grrrrh) try to do heaps more than byte-array send and recieve (they try to enforce your way of doing threads as well as message to byte array conversion and vice versa).

Great work  Cool


Offline blahblahblahh

JGO Coder

Medals: 1

« Reply #2 - Posted 2008-01-22 11:00:30 »

I'm going to be needing UDP myself in the near future I'm sure - but so far, for simple casual games written quickly, it has been "OK" just to use TCP. *shudder*.

(...but it's interesting following the scrum / agile / "only make exactly what you need right now and no more" to it's most extreme Smiley).

malloc will be first against the wall when the revolution comes...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline sunsett

Senior Devvie


« Reply #3 - Posted 2008-01-30 20:36:28 »

JGN supports straight byte[] sending/receiving. Wink

Further, it has complete UDP and TCP support in NIO....not that I'm biased.  Roll Eyes
Offline blahblahblahh

JGO Coder

Medals: 1

« Reply #4 - Posted 2008-11-27 13:54:54 »

Now moved to SourceForge:

...and I'll be doing an SVN check-in (once I can get my Mac to connect to the SF SVN servers) so you'll be able to pull the source out via SVN if that's your preference (hint: I'd strongly suggest this is a good idea Wink).

If anyone's been using this and has made any improvements they want to share, send SVN commits via sourceforge (I'll add anyone to the project as necessary).

malloc will be first against the wall when the revolution comes...
Pages: [1]
  ignore  |  Print  

hadezbladez (289 views)
2018-11-16 13:46:03

hadezbladez (157 views)
2018-11-16 13:41:33

hadezbladez (290 views)
2018-11-16 13:35:35

hadezbladez (71 views)
2018-11-16 13:32:03

EgonOlsen (2150 views)
2018-06-10 19:43:48

EgonOlsen (2152 views)
2018-06-10 19:43:44

EgonOlsen (1364 views)
2018-06-10 19:43:20

DesertCoockie (1983 views)
2018-05-13 18:23:11

nelsongames (1600 views)
2018-04-24 18:15:36

nelsongames (2248 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 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‑
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!