Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (523)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
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  
  A great networking framework. !  (Read 3934 times)
0 Members and 1 Guest are viewing this topic.
Offline NewbTon

Junior Devvie




Odejava games rock!


« Posted 2006-04-23 20:48:35 »

Many of you propably already know about it, but for the ones who dont : try
Mina from Apache. It uses java.nio and it's is absolutely marvelous and very easy to learn.
And I used to play around with sockets and datagrams, actually thinking I could make something
useful on my own..  Grin.
Offline noblemaster

« JGO Spiffy Duke »


Medals: 20
Projects: 10


Age of Conquest makes your day!


« Reply #1 - Posted 2006-04-23 21:19:07 »

Same here! MINA is great!

Offline Kova

Senior Devvie





« Reply #2 - Posted 2006-04-24 08:46:56 »

everybody with some effort can make their own stuff... like me. When I started I knowed nothing, then started to read tutorials and worked my way up. Now I have good server/client I can use, only thing left to do is work on the game and determine what messages to send Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline harry@dayfamilyweb

Junior Devvie





« Reply #3 - Posted 2006-04-24 08:49:43 »

can i have a link please
Offline noblemaster

« JGO Spiffy Duke »


Medals: 20
Projects: 10


Age of Conquest makes your day!


« Reply #4 - Posted 2006-04-24 08:59:04 »

Apache MINA: http://directory.apache.org/subprojects/mina/

Offline CommanderKeith
« Reply #5 - Posted 2006-04-24 09:26:12 »

I tried MINA and couldn't make head or tail of it even after reading for hours.  There are too many layers.

I found the network code here to be the most simple, but it's only TCP.

http://www.java-gaming.org/forums/index.php?topic=4120.new;boardseen#new

I was thinking that there should be a thread to show-case of all of the different network API's and how to use them.  That way people like me could see how to use MINA and other API's and diectly compare them using the same example game.... just a thought  Smiley

Keith.

Offline NewbTon

Junior Devvie




Odejava games rock!


« Reply #6 - Posted 2006-04-24 10:51:24 »

Many people can't figure out whats it about because it doesnt use tradidional  stream based socket programming
You dont make any blocking calls at all.
You register a serversoclet with you IoHandlerAdaptor, which implements methods like
sessionStarted(Session session)
sessionClosed(Session session)
messageReceived(String message)

That you of course have to override.

Each session has a user object , or sevaral, associated with it.

This is totally the same as registering an an ActonEvent with a JButton.

This model is  particularly useful in  mmorpg 's were  you might handle 20.000 connections at the same time.
Imagine how much resources it would take from your  java program. 20.000 sockets and 20.000 threads. Forget about it.
Asynchrone communicanation like Mina takes care of that. Now you can go from 20.000 threads/sockets to 1  !!

Along with that Mina supports ssl and various protocols, like HTTP/FTP etc.
Offline aldacron

Senior Devvie


Medals: 9
Exp: 16 years


Java games rock!


« Reply #7 - Posted 2006-04-24 10:57:12 »

Asynchrone communicanation like Mina takes care of that. Now you can go from 20.000 threads/sockets to 1  !!

Not exactly. You'll ditch the threads, yes. But you still need a socket per connection if you are using TCP. This is exactly what java.nio allows you to do with Selectors and Channels. MINA just wraps it all up for you.
Offline NewbTon

Junior Devvie




Odejava games rock!


« Reply #8 - Posted 2006-04-24 11:37:04 »

OK didnt know that. But the threading is also the heavy area, right ?
Offline Mr_Light

Senior Devvie


Medals: 1


shiny.


« Reply #9 - Posted 2006-04-24 20:26:21 »

20.000 to 1 thread is just as bad as you stuck on one processor with that one thread?
its done to avoid context switching costs and what not, not to avoid writing multithreaded code.
( I don't mean it as hash as it might sound).

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline NewbTon

Junior Devvie




Odejava games rock!


« Reply #10 - Posted 2006-04-24 21:55:25 »

I'm not sure what you mean. One thread can never be as bad as 20.000 threads  Huh
Offline noblemaster

« JGO Spiffy Duke »


Medals: 20
Projects: 10


Age of Conquest makes your day!


« Reply #11 - Posted 2006-04-24 22:26:01 »

Quote
Along with that Mina supports ssl and various protocols, like HTTP/FTP etc.

That's particularly cool about MINA! With couple lines of code, I could add SSL! I programmed my own java.nio library a while back - but why reinvent the wheel everytime? Never got to the point to add SSL, the packet size was limited to 32000 bytes .. MINA is way better.

Offline Mr_Light

Senior Devvie


Medals: 1


shiny.


« Reply #12 - Posted 2006-04-24 22:47:34 »

I'm not sure what you mean. One thread can never be as bad as 20.000 threads  Huh

1 thread per client scales just as bad as one thread for the whole app.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 832
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #13 - Posted 2006-04-24 23:00:54 »

I'm not sure what you mean. One thread can never be as bad as 20.000 threads  Huh

1 thread per client scales just as bad as one thread for the whole app.

Couldn't be farther form the truth. Try to launch 20.000 threads and let them all sleep. You'll see 100% cpu-usage. No way it's "just as bad".

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline aldacron

Senior Devvie


Medals: 9
Exp: 16 years


Java games rock!


« Reply #14 - Posted 2006-04-25 01:27:05 »

Quote from: Mr. Light
1 thread per client scales just as bad as one thread for the whole app

Obviously there's a finite limit on how many connections a single thread can handle, either due to consumption of available resources or limitations of the underlying network API. No one said you have to use a single thread to manage connections, just that there's no need to use a thread per connection. I've seen designs that manage connections in groups (where a group is a set number of connections, like 64, 128, 1024, or whatever), using two threads per group - one for receiving and one for sending.

The point is that one thread per connection does not scale well at all, but multiple connections per thread does.
Offline Jeff

JGO Coder




Got any cats?


« Reply #15 - Posted 2006-04-25 02:55:19 »

Thread switchign itself takes some CPU.

The ideal number of threads for any system is a number of ACTIVE threads equal to the number of CPU cores, no more and no less.

Ofcourse its pretty hard to hit that perfect number. Any thread doing any kuind of IO is going to spend some period of time waiting for hardware.  Thats time that is wasted unless you have other threads to use the core duing those waits BUT unecessary swapping costs you performance.

In short, tuning thread usage is very much a per-system, per-app and per-situation thing.

MINA is simply an abstraction layer ontop of NIO.  Its NIOP which allows you to serve multiple sockets from the same thread.  Whether or not the abstraction layer is advantageous or disadvantageous wil ldepend on your individual knowledge level and needs.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Mr_Light

Senior Devvie


Medals: 1


shiny.


« Reply #16 - Posted 2006-04-25 20:43:37 »

Couldn't be farther form the truth. Try to launch 20.000 threads and let them all sleep. You'll see 100% cpu-usage. No way it's "just as bad".
on my 20.000 core system it runs perfectly fine.  Wink

Quote from: Mr. Light
1 thread per client scales just as bad as one thread for the whole app

Obviously there's a finite limit on how many connections a single thread can handle, either due to consumption of available resources or limitations of the underlying network API. No one said you have to use a single thread to manage connections, just that there's no need to use a thread per connection. I've seen designs that manage connections in groups (where a group is a set number of connections, like 64, 128, 1024, or whatever), using two threads per group - one for receiving and one for sending.

The point is that one thread per connection does not scale well at all, but multiple connections per thread does.

your guys are missing the point I'm making.

where did I preach  that 1 thread per connection is the way to go or any good.

if you have or rather need to have 20.000 concurrent connections with need you apperently need to send some data I doubt there is any affordable processor who has one core that can handle all that. So esp in terms of scaling. 20.000 connections on 20.000 threads is just as bad as 20.000 connections in 1 thread.

offcourse other ratios are much better, as jeff and riven/yourserf  indicate. these ratio's iether way you end up with one or more thread thus you need to take into account multi threading and thread savety. Some ppl seem to proclaim that oe 1 thread per connection sux (which it does wenn you expect many connections) and then make the crazy conclusion that everything needs to be in one thread and that they don't need to learn to write multithreaded code.

appearandly it doesn't come as obvious to some.

and The point is that one thread per connection does not scale well at all, but niether does sticking to one thread.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline NewbTon

Junior Devvie




Odejava games rock!


« Reply #17 - Posted 2006-04-25 21:35:48 »

Since Mina handles everything through callbacks I dont think you can say everything is handled even in one thread.
You can create a NIO program without a single thread.
The concept of sockets/connections  is just not used in NIO. Every  "connection"  is just a mapping to a session, so context switching can be handled that way. Every packet is just routed to the right  "owner"  without any delay/overhad, and the t fastest possible way.
That way you dont have context switching and threads waiting/sleeping anymore, which is the real hurdle plus there's danger of deadlocks all the time.
This is just my own interpretation, correct me if im wrong.

But other than that I think that it's widely accepted that NIO scales WAY better than traditional socket/stream apps. I know it scaled my application very well.
Offline harry@dayfamilyweb

Junior Devvie





« Reply #18 - Posted 2006-04-25 21:55:48 »

it is OK but the tutorial is terrible and how do you use Streamhandler
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.

SHC (21 views)
2014-11-25 12:00:59

SHC (19 views)
2014-11-25 11:53:45

Norakomi (18 views)
2014-11-25 11:26:43

Gibbo3771 (21 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (74 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (41 views)
2014-11-12 21:09:33

kovacsa (67 views)
2014-11-07 19:57:14
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!