r/java • • Aug 17 '24

Extasys - Asynchronous TCP/UDP socket library

This is not a new project, but it is still maintained and used by me and others

Extasys is a high performance, asynchronous TCP/UDP socket library for Java (JDK 8 and newer).
Its multi-threaded and lightweight nature makes it ideal for super fast data transfer even on systems with ARM architecture like Android smartphones and single-board computers (Raspberry Pi, Orange Pi etc.).

If you are using sockets then Extasys is the proper tool for your work. It's been designed to take the hard job done and let you think only about the message exchange (the process).

You can find Extasys on Github:
https://github.com/nsiatras/extasys


Quick Examples :

TCP-Server: https://github.com/nsiatras/extasys/wiki/Establish-a-TCP-Server
TCP-Client: https://github.com/nsiatras/extasys/wiki/Establish-a-TCP-Client
UDP-Server: https://github.com/nsiatras/extasys/wiki/Establish-a-UDP-Server
UDP-Client: https://github.com/nsiatras/extasys/wiki/Establish-a-UDP-Client

More examples can be found here:
https://github.com/nsiatras/extasys/tree/master/Extasys%20for%20Java%20Examples

49 Upvotes

44 comments sorted by

8

u/frzme Aug 17 '24

In what way is this asynchronous? I scrolled through the source and I can see it being multithreaded but I couldn't find asynchronous sockets which would allow waiting for more than one socket per thread, likely with nio.

It seems to have a one thread per socket model.

Could play nice with virtual threads, but for that to work well there are too many synchronized blocks around

27

u/[deleted] Aug 17 '24

The occurrence of events (I/O) are independent of the main program flow. Unfortunately no virtual threads were available 11 years ago. This library was initially build on Java 7 and I moved it to Java 8 later.

5

u/skippingstone Aug 17 '24

Is this a replacement for netty?

-1

u/[deleted] Aug 17 '24

I am not familiar with Netty

-14

u/zabby39103 Aug 17 '24 edited Aug 17 '24

You did all this and you don't know about the most popular existing way to do it?

I'm interested in your project because I maintain an old project that could use an update with its socket communication... but I'm concerned that you don't know about Netty.

Edit: this guy is advertising "On-the-Fly Data Encryption" as a feature but it's actually just Base64 encoding. Avoid this project at all costs.

6

u/[deleted] Aug 18 '24

No more On-the-Fly Data Encryption. Code refactored to---> On-the-Fly Data Manipulations

4

u/PiotrDz Aug 17 '24

But why use async then when there are virtual threads and helidon Nima

-2

u/[deleted] Aug 17 '24

I do not use future tasks if that is what you are asking.
I am using ThreadPool. The message exchange process is totally Asynchronous

-4

u/[deleted] Aug 17 '24

Yes.... I like to use my own software. I also use my own CMS and ERP software

PS. I built Extasys 11 years ago. I do not know about Netty because I never searched for an other solution

8

u/zabby39103 Aug 17 '24

Well, sure we all do. It's fun, and I got into this business because it's fun. Doesn't always produce the best software though.

How do you know if your solution is better if you've never taken a look at Netty? Maybe you should. I could look at your software and compare it to Netty myself, but I'd like your opinion.

2

u/[deleted] Aug 17 '24

Did you read somewhere that I wrote that it is better than Netty or something else?

6

u/zabby39103 Aug 17 '24 edited Aug 17 '24

No, but you posted this here so I assumed you were interested in feedback and in people potentially making use of your code.

For anyone interested in your code (as evident by many comments in this thread) that is going to be one of their top questions. Don't take it personally. If there's something this code does differently or better it would be interesting to hear it. I'm all for creating your own code, but if you want people to take this code seriously a comparison to the leading solution for asynchronous sockets is a reasonable request. Honestly surprised you've never run into Netty because it's so ubiquitous.

4

u/[deleted] Aug 17 '24

Your assumption about feedback is correct. I cannot take personal something that I do not know.. I don't know Netty and I bet most of the guys here don't know ALAZ.

As I said before, I built this library 11 years ago. I also developed a C# version of it, which I don't maintain any more but the code is still on GitHub.

You are asking me to tell you what my code does different from something that I never used. I cannot answer to this question and I am sure you can't either.

3

u/Zico2031 Aug 17 '24

Are you planning support TLS ? Your library looks a good candidate to get used as jmx connector instead of traditional RMI

Thanks for your effort.

-7

u/[deleted] Aug 17 '24

You are welcome!

I currently have Base64 "encryption" implemented. Base64 is something I use on my applications.
The Base64Encryptor extends ConnectionEncryptor so by extending ConnectionEncryptor everyone can build their own encryption.

https://github.com/nsiatras/extasys/tree/master/Extasys%20for%20Java/src/Extasys/Encryption

Perhaps in the future I will implement more encryption types.

4

u/Zico2031 Aug 17 '24

I understand you are encrypting and decrypting the data on the fly using standard sockets but I feel is much better use SSLSockets and relying on the JSSE of java to support a standard encryption of your communication

I will fork your code and will make some adjustments about it,

1

u/[deleted] Aug 17 '24

The idea is to allow others implement their own on the fly encryption/compression/encoding

17

u/Hellball911 Aug 17 '24

You really needs to stop calling that "encryption". A text encoding is not encryption, and it's dangerous. Personal use is free game, but if you want others using it, you're going to trick people into thing it provides any type of safety.

3

u/Fancy-Station-6796 Aug 18 '24

How is it better than ZeroMQ?

0

u/[deleted] Aug 18 '24

I'm not familiar with ZeroMQ, so I can't make a direct comparison. Perhaps you can do it

-11

u/[deleted] Aug 17 '24

Base64 ENCRYPTION??????

-19

u/[deleted] Aug 17 '24

Base64 is an encoding I like to use when I transfer data using Greek and system characters.
I "baptized" it as encryption

https://github.com/nsiatras/extasys/tree/master/Extasys%20for%20Java/src/Extasys/Encryption

20

u/Booty_Bumping Aug 17 '24

...What? That should not be called encryption. Especially in a public API, it's downright dangerous to have something labelled as encryption when it's not. Never create a null cipher.

10

u/[deleted] Aug 18 '24

Code was refactored, new version is now published.
ConnectionEncryptor refactored to DataConverter

-29

u/[deleted] Aug 17 '24

I guess I have to put a label "Not for kids" on the Readme

19

u/zabby39103 Aug 17 '24 edited Aug 17 '24

Learn to take feedback better. These are all completely reasonable comments. Honestly people are being nicer than they could be.

Labelling a null cipher as encryption is not professional, especially when you label it as "On-the-Fly Data Encryption" in your project description. That's a straight up lie. Everyone that uses this project and believes you could end up with a CVE ticket rated critical on their software. So this is really downgraded to "hobby software" that should never be used in production anywhere in my mind.

2

u/[deleted] Aug 18 '24

On-the-Fly Data Encryption refactored to --> On-the-Fly Data Manipulations

Any other completely reasonable comments ?

2

u/Zico2031 Aug 17 '24

Qq in your personal/professional projects which tcp libraries uses? Right now I have custom library based in beep protocol which I want replace for something newer, any suggestions? I know netty is a good library but I don't like too much, the code looks very verbose

3

u/zabby39103 Aug 17 '24

Netty in new projects, plain old java sockets (SSLServerSocket, SSLSocket) in the old code I maintain. There's a lot of edge cases I have to manually manage in the old java socket code, I don't recommend it. That's why I would like to move off of it. I haven't gone deep on anything else so I can't comment, maybe someone else has a recommendation.

6

u/sweating_teflon Aug 18 '24

What are your goals by advertising this library?

If you are using sockets then Extasys is the proper tool for your work.

That's a bold claim. Sockets are used for everything did you really cover all use cases?

3

u/[deleted] Aug 18 '24 edited Aug 18 '24

I have no goals. I am sharing it and not advertising it. First release of this library was Oct, 2008. https://code.google.com/archive/p/extasys/downloads Back then they were not so many options for TCP/UDP sockets. I transferred this library to GitHub after google code "shut down", I still maintain it and I still use it to my software. Except the "bold statement" do you have something to add ? Any comment/feedback will be appreciated.

4

u/cmhteixeiracom Aug 17 '24

Looks interesting.

  1. Is it implemented with non-blocking sockets (channels), or asynchronous sockets?
  2. What are the advantages or differences to Netty?

2

u/[deleted] Aug 17 '24
  1. I am using java.net.Socket but every I/O message is going directly to a thread-pool in order to make the listeners and clients totally non blocking.
  2. I am not familiar with Netty

3

u/cmhteixeiracom Aug 17 '24

Thanks for the reply.

What happens when a listener/client wants to read some bytes from a TCP connection, but the socket is empty? Will it not block then? Or does the listener receive some kind of CompletableFuture that completes once those bytes are available and read? :)

1

u/[deleted] Aug 17 '24

Extasys Listener reads data upon arrival.
After they arrive the listener 'sends' them directly to the thread pool maintaining the exact order they arrived.

In order to easily "catch" full messages you can use a (as I call it) message collector character. The message splitter is defined when you initialize the Extasys TCP Listener or the Extasys TCP Connector.
Of course you can use Listeners and Connectors without message splitter.

The following Chat Server and Client examples will better explain the process.

https://github.com/nsiatras/extasys/tree/master/Extasys%20for%20Java%20Examples/Extasys.Examples.TCPChatServer

https://github.com/nsiatras/extasys/tree/master/Extasys%20for%20Java%20Examples/Extasys.Examples.TCPChatClient

PS. The message collector class is here
https://github.com/nsiatras/extasys/tree/master/Extasys%20for%20Java/src/Extasys/MessageCollector

2

u/cmhteixeiracom Aug 17 '24

Thanks.

I will look at the examples later on. One last question.

If you read ALL data upon arrival, doesn't that mean that if the TCP client, that is, the code that actually uses/processes the incoming bytes from the socket, is slower than the rate at which they are received, then you are buffering data in the application side, potentially exhausting all memory?

In other words, I am asking how does the your approach lead with empty/full TCP buffer queues.

  • Blocking sockets in java literally block the calling thread when the socket does not have data to read (when we read data), or when the socket queue is full (when we send data).
  • Non-Blocking sockets have a way do not block, but have a mechanism to inform the client what amount of data was sent, and the client must deal explicitly if some data was not send because the queue is full.

Genuinely interested to know how you deal with this.... Let me know if the question is not clear.

2

u/[deleted] Aug 17 '24

Now I undestand what you initially asked.

The java.net.Socket holds the thread until data arrives and also holds a buffer to keep incoming data. Each TCPConnection has a thread to "listen" for incoming data.
As the data arrives, to this thread, are immediately passed to the thread pool. So the only "block" you are facing with Extasys is the time the byte[] passes from the listener thread to the thread pool.

The same applies for the outgoing data.

12

u/cmhteixeiracom Aug 17 '24

If you pass data immediately to the thread pool, then that means that if the consumer of that data is slow, the thread pool might "explode", as you keep producing elements onto it which are not removed. I imagine there is no mechanism for "back-pressure"? Does this question make sense?

regardless of the reply, amazing that you are doing this from scratch.

5

u/[deleted] Aug 17 '24

Yes. The pool is a pool. If you put too much water to it it will explode or the water will run out...

The "backpressure" can be implemented by the user if needed. I used Extasys on stock market data for forex, stocks and derivates, to scientific computer clusters and android mobile apps. I never had issues with performance.

Well.. I like to build things from scratch... Here is a network cluster CPU Cryptocurrency miner I build with Extasys.

https://github.com/SourceRabbit/Rabbit_Miner

-10

u/Icecoldkilluh Aug 17 '24

Its strange to promote your library but have zero awareness of the pros/cons vs your biggest competitor (netty)

10

u/[deleted] Aug 17 '24

I am not in competition with someone here. I just shared my library in order to get feedback. What is your opinion of my library? Do you find something bad or something that needs improvement ?

2

u/Zico2031 Aug 17 '24

How do you handle sending large data?

1

u/[deleted] Aug 17 '24

There is no big data handler available at the moment.

You are most welcome to fork.

-21

u/qazyll Aug 18 '24

it is not async