NIO versus NET?

X

XELON

Hi,

I'm working on an instant messaging program. It is part of my senior
project. I want to write the server with Java. But I can't decide to
use ServerSocket or Channels(NIO). I searched google and find some
information. They say using NIO is more efficient. But the client side
of software might be written with C, C# or Java. If I use nio instead
of net package, can i connect the server with TCP via any programming
languages' TCP libraries?

And which method do you advice? (nio or net)

To send the message through server, there must be 2 established
connection between users and server. Server is going to keep the
established connections with ArrayList or Vector. If a user(say usr1)
sends a message to another user(say usr2), first the server takes the
message from usr1 and finds the name of recipient from message, and
find the connection between server and usr2 on Vector or ArrayList with
user name. And sends the message to usr2. Is this a correct way of
messaging?

Thanks
 
T

Thomas Hawtin

XELON said:
Hi,

I'm working on an instant messaging program. It is part of my senior
project. I want to write the server with Java. But I can't decide to
use ServerSocket or Channels(NIO). I searched google and find some
information. They say using NIO is more efficient. But the client side
of software might be written with C, C# or Java. If I use nio instead
of net package, can i connect the server with TCP via any programming
languages' TCP libraries?

It's all TCP/IP on the wire. It doesn't matter how each end is written.
And which method do you advice? (nio or net)

Go for java.net. There are ways java.nio can be more efficient (in terms
of CPU cycles), but it is unnecessarily complicated for most problems.
To send the message through server, there must be 2 established
connection between users and server. Server is going to keep the
established connections with ArrayList or Vector. If a user(say usr1)
sends a message to another user(say usr2), first the server takes the
message from usr1 and finds the name of recipient from message, and
find the connection between server and usr2 on Vector or ArrayList with
user name. And sends the message to usr2. Is this a correct way of
messaging?

Sounds reasonable. However, if you have the same thread that reads the
message from the sender also write to the recipient, any delays relaying
the message will prevent the next message being read. So it's normal to
have two threads for each connection.

Tom Hawtin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Upload using java nio 10
NIO UDP and TCP 5
JAVA NIO 4
NIO 12
Simple NIO sockets example. 0
NIO - Selector.select() doesn't block 7
Echo Server Using NIO 1
nio questions 10

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top