-3

I have some very basic doubts on this topic. I have a legacy server written some 30 years ago in C, C++, that supports socket communication but it works great. I am in the process of writing a new java based client to connect to this server basically the goal is to expose the services (REST etc) for enterprise applications.

1) Should i go for plain java socket based approach or use Netty or Apache-Mina, what benefits i may have by using these modern apis in this scenario.

2) When using NIO based IO, does the sever also need to be a NIO based to take advantage of it or a NIO client to a legacy server (non NIO) would just work as good as it does with a NIO server.

Thank you very much

Mark1234
  • 589
  • 2
  • 8
  • 24

1 Answers1

2

1) Should i go for plain java socket based approach or use Netty or Apache-Mina, what benefits i may have by using these modern apis in this scenario.

I assume that you mean using plain Java sockets to implement HTTP / REST-ful APIs.

That is a bad idea. It is theoretically possible, but you will end up doing a large amount of unnecessary coding. And the chances are that you will not implement the HTTP 1.1 spec properly ... and that will lead to further problems.

As for the others, I'd take a look at them, compare their features against the features you need and decide based on that ... and how easy to use they look like to yout.

2) When using NIO based IO, does the sever also need to be a NIO based to take advantage of it or a NIO client to a legacy server (non NIO) would just work as good as it does with a NIO server.

What you do on the client and server sides (NIO versus non-NIO) is independent of each other. Indeed, if you do REST properly, the client and server sides shouldn't even need to be programmed in the same language!

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Thanks, I should not have mentioned RESt part, that's an additional layer that may be built later to sit on top to provide additioanl ways to access a java client, lets ignore that for now. Question is plain java socket based client or a NETTY or MINA style client. – Mark1234 Jul 22 '14 at 14:11
  • Same answer really. The unnecessary work us in the HTTP stack that you would need to implement for yourself on top of sockets. – Stephen C Jul 22 '14 at 14:32
  • Ok, thanks. So NIO is totally independent between server and client, sounds like a stupid doubt but i did not got the answer anywhere so i asked it here. Thanks. Once i have my socket client method implementation that get me some data using socket based mechanism i will use some restful api to expose it as a rest service so anyone could use it. Not really sure where you see unnecessary work. – Mark1234 Jul 22 '14 at 14:47
  • 1
    @user3777305 - I've already answered that. The extra work is that you have to implement an HTTP (server side) stack on top of the sockets in order to do REST. REST requires HTTP underneath ... or it isn't really REST. Perhaps you should **read** the HTTP 1.1 specification for yourself to get a handle on how much work would be involved. (You'd have to do this anyway ...) – Stephen C Jul 22 '14 at 21:57