3

I need to implement a TCP server with a web interface included for management.

Basically, the tcp server will be listening to new connections and keeping current ones active while the web interface allow me to see information regarding these connections and to interact with them (e.g. send messages and seeing received ones)...

My concerns resides in the "TCP Server" integration with the web application. For received messages I could simple use a shared DB, but I need to send messages to the peers connected into the TCP server.

My best bet is currently on JCA. Some research pointed me to a nice sample: http://code.google.com/p/jca-sockets. The sample uses an Message Driven Bean to deal with messages received over port 9000, acting as an echo server.

I am new in the Java EE 6 world. I trying to figure out why things were done in one way or another in the sample (e.g. why MDB?).

JCA has a fairly complicated spec. So I am trying at first to adapt the sample above to keep the connections active to exchange data. My next step will be adapt it to accept a string over a servlet to forward it to a given peer.

Can someone help me out on this?

chrisandrew.cl
  • 867
  • 14
  • 30
  • Why do you want to make a 'simple' management UI that complex - especially if you have a challenging schedule? Maybe plain old JSP+HTML is an option you should consider? – home Feb 23 '12 at 16:56
  • I agree. I've suggested what I've known as "ideal", but, really, any thing useful regarding that matter will help me. Also, the JSF + Richfaces thing is due the usability factor. My frontend skills are nearly null, so I expect to use some out-of-the-box nice looking APIs... – chrisandrew.cl Feb 23 '12 at 17:00
  • Agree as well. IMHO it's easier to create a simple JSP+HTML UI, especially if you're not experienced with 'modern' UI technologies. It's just less complex and not that much to learn - tradeoff is that it's not that fancy... – home Feb 23 '12 at 17:14
  • No, it isn't, I am no student. I am just trying to accomplish something I suspect could (or should) be easy (or at least not so complicated)... – chrisandrew.cl Feb 24 '12 at 16:28
  • You're barking up a big tree with a steep learning curve... If it is a simple web server consider Tomcat with some simple JSP or JSF. You don't need a huge leap in complexity until you understand why you need it. (Chances are you don't need it) – Daniel B. Chapman Oct 07 '12 at 04:48
  • @DanielChapman My concerns are now focused in the integration of the TCP Server and web app. I've updated the question to reflect this. I will be using Glassfish or JBoss. – chrisandrew.cl Oct 07 '12 at 04:57
  • Its a crap-shoot either way. There's great feature sets in both and they are effectively "the same" at the end. I prefer JBoss and have been impressed with JBoss7 for what that's worth. Do a tutorial and get a hello world with JSF set up. RichFaces is nice, but I prefer Primefaces (more work, nicer jQuery UI components). – Daniel B. Chapman Oct 07 '12 at 15:37
  • @DanielChapman I edited this question to wipe out every piece of text regarding JSF or JSP matter. If simple JSP, Servlet or JSF for presentation isn't the concern. I need help in the integration between TCP Server and Web Application. Isn't it clear? Maybe I should create another question? Don't think me rude, I am asking for feedback if the question is clear or if should I rephrase it. – chrisandrew.cl Oct 07 '12 at 18:21
  • http://docs.oracle.com/javase/7/docs/api/java/net/Socket.html I don't think you've specified what you're actually trying to accomplish. Use a socket and implement whatever you need. You can, of course, do that over an EE server but I'd definitely ask why before I started implementing it. There's usually a much better solution. – Daniel B. Chapman Oct 09 '12 at 02:07
  • As far as I know, one can't simple open a socket in standard web container. Doing it in JavaSE is simple, but it's EE not SE. I need it integrated with the web app to provide it easily over any browser. – chrisandrew.cl Oct 09 '12 at 03:46

1 Answers1

3

Well, first of all, using Java EE with TCP is not the best approach you may use. If you just need a simple TCP service with Web UI you'd better consider using Java SE with some web container attached (undertow works well).

In other hand, if you need your application to integrate into existing Java EE infrastructure your company has, JCA would be the best approach. While it's not designed for such kind of things, JCA is the only EE subsystem liberal enough for that kind of thread management you would need for TCP networking to work.

JCA-Socket you're referring above is not the best example of a JCA app. It uses plain Java's blocking sockets by blocking WorkManager thread, this is not very effective. Things got much better now and we have Java NIO and Netty for highly effective raw networking to work upon. I have a JCA connector for TCP interactions which may provide you a skeleton to build your own. Feel free to extend and contribute.

P.S. About MDB: message-driven bean is the only "legal" JCA approach of asynchronous incoming messages handling. Since TCP is asynchronous, you'll definitely need one in your application for all the things to start working. Outcoming data transfers happen through various ConnectionFactory interfaces you'll inject into your bean. The link above will provide you with a reference ConnectionFactory implementation as well as a simple tester app utilizing both ConnectionFactory and MDB messaging approaches.

Roman Nazarenko
  • 608
  • 4
  • 11