Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (555)
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  
  Some general Java NIO questions  (Read 1473 times)
0 Members and 1 Guest are viewing this topic.
Offline cookie

Junior Member


Medals: 1



« Posted 2013-05-23 11:05:19 »

Hello,
today I have started with Java NIO, but it seems to be quite complex, hence I have some questions to which I couldn't find any answer in those NIO tutorials I have read.

For learning purposes I want to implement some very common use cases:

1. Sending serialized objects to a server, deserializing and storing them in a collection.    
2. Requesting data from a server. The data could be anything, maybe some objects in an array.

I don't understand how ObjectInputStream/ObjectOutputStream and ByteBuffer work together and I'm not sure how many channels I need on the client and on the server. Do I need one socket channel on each side for each use case (4 socket channels altogether) or would one read-write-socket channel on each side be sufficient?

Thanks for all answers.



Offline Riven
« League of Dukes »

JGO Overlord


Medals: 783
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2013-05-23 11:14:18 »

Why did you decide to use NIO? It's not a natural progression from old IO. You're better off without it, even if you merely want to learn it for the sake of it - just don't. At least, not until you have a solid understanding of old IO, and a specific need for new IO.

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

Junior Member


Medals: 1



« Reply #2 - Posted 2013-05-23 11:23:54 »

Normal sockets need multiple threads to handle multiple clients concurrently, which would result in a cumbersome and resource-hungry multithreading implementation.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 783
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2013-05-23 12:05:20 »

Unless you actually have thousands of concurrent connections, it's premature optimization.

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

Junior Member


Medals: 1



« Reply #4 - Posted 2013-05-23 12:22:57 »

My goal is to get just a basic practical understanding of how this works, because it doesn't have a lot in common with standard Java sockets. It just aroused my interest, the practical usage is another question.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 783
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2013-05-23 12:27:50 »

Given the questions in your first post (how to connect Streams to Channels, and whether to use 1 or 2 sockets per client), I'm fairly sure you simply need to study old IO and get real world experience with it (not just a simple request/reply server), before even considering NIO. Once you have experience with old IO, you'll see that NIO is not that different and all NIO tutorials will make sense.

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

Junior Member


Medals: 1



« Reply #6 - Posted 2013-05-23 12:36:16 »

That was a typo and I already changed that. I did not mean sockets, but socket channels.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 783
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2013-05-23 12:57:43 »

Same thing really. A NIO channel is an InputStream and OutputStream wrapped into one.

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

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #8 - Posted 2013-05-24 00:36:31 »

Normal sockets need multiple threads to handle multiple clients concurrently, which would result in a cumbersome and resource-hungry multithreading implementation.

With the new concurrent libraries and executor services threading is a piece of cake. You can now write a standard IO socket based server with threading that is dead simple compared to the old thread way or even with NIO.

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.

Nickropheliac (13 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (27 views)
2014-08-22 19:31:30

atombrot (40 views)
2014-08-19 09:29:53

Tekkerue (38 views)
2014-08-16 06:45:27

Tekkerue (34 views)
2014-08-16 06:22:17

Tekkerue (24 views)
2014-08-16 06:20:21

Tekkerue (34 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (47 views)
2014-08-09 21:09:32
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!