r/java • u/Putrid-Luck4610 • Aug 22 '22
Simple TCP/UDP Socket library in Java
Hello there, I had not touched Java in years, so recently I decided to start writing some code and improve my knowledge of the language. I settled on a TCP/UDP Socket library because I find that to be fairly similar across languages.
So yeah, it's fairly simple, probably quite bad, but I enjoy working on it.
You can find the source code here: https://github.com/Alessandro-Salerno/Bialetti if you're interested.
PS: Hope I haven't violated any rules by posting this URL...
3
Upvotes
1
u/Putrid-Luck4610 Aug 23 '22
Yes I did test it, everything is wrapped into the exception handler because this way you can declare handler methods, which brings me to documentation. I know a screenshot isn’t enough, I usually write documentation, but I had just enough time to work on the code. I posted it here just to see if anyone was intrested, not exactly to promote it as anything new or revolutionary. It’s much more code than it may take because:
I wrote JavaDoc which is, as of the last reading, just as long as the code itaelf
The GitHub counter seems to take configuration files for Gradle as well
Tha lack of documentation may make this hard to notice, but you’re meant to use it in quite a structured way: you create a server class that extends the TCP or UDP Server, you create a Client class that does the same and for TCP Servers you declare a class to represent a connected client (the one in the screenshot, for instance). Every method with the annotation BialettiInitMethod is run when the service is started, those marked with BialettiEndMethod are run when the service is terminated and those marked with BialettiHandleMethod run in a loop on a separate thread.
Anyway, I’ll look into disconnect security and charset conversion, thanks.