cubesky / SocketChannel

An easy used library for Java NIO and it can also easily create Normal IO Socket
GNU General Public License v3.0
9 stars 5 forks source link

Raw Socket #3

Open nhatnd20 opened 5 years ago

nhatnd20 commented 5 years ago

Hi, I am new to socket programming, what is the purpose of Raw Socket? (createUnmanagedSocket method)

cubesky commented 5 years ago

First, beacuse NIO is single-thread socket managment, if you want to transport huge bits of data, it will block all other read and write event.
Second, SocketChannel Library used a byte-base protocol for automatic heartbeat and some file transport header, you can not access raw socket, so you can not implement some protocol by your self, createUnmanagedSocket can give you a raw connection. By the way, file transport is also depends on this feature by running on an independent thread to avoid blocking other connection.

cubesky commented 5 years ago

NIO is designed to manage large numbers of connection, but these connection transport small bit of data and it doesn't transport all the time.

nhatnd20 commented 5 years ago

thanks for the clear explanation. But I see you have created a lot of new Thread(), it will affect the performance of the program ?

cubesky commented 5 years ago

In SocketChannel, I use Thread Pool to run some code, it will reuse thread instead of create it. Some new Thread() is pass the data to another thread to avoid blocking reading event from connection manage thread. It should affect some performance, so I scheduled to fully rewrite this library due to performance issue and some poorly expandability design.

cubesky commented 5 years ago

Unfortunately, I don't have enough time to do these now.
I have planned to use listener design to improve the possibility for more protocol support and give more simplify data processing workflow.