Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java TCP server program running on Apache Tomcat

Here i have some problem with TCP server program, i have created a jar which is having the TCP server code and this need to be run continuously and i need to deploy this jar in apache server... this jar will works fine when we execute the jar from command prompt ans will not accept the incoming connections when its running apache tomcat,in apache i have already some jars running so they are not at all dependent on this jar.

while (true) {
    Socket client = serverSocket.accept();
    System.out.println("S: Receiving...");

----------
like image 353
Venkatesh Dayawar Avatar asked Sep 04 '26 08:09

Venkatesh Dayawar


1 Answers

We did this successfully for a chat program a couple of years ago but it was a nightmare to maintain. There are several other more standardised ways of doing this. From the top of my head here is what we did.

  1. Created a servlet
  2. In the servlet init function created a thread that services the socket.

You can see a example of this here Connecting to socket on Tomcat?. Also read this discussion How to listen a socket in Tomcat(servlet container)?

Some alternatives would be to google the following:

  1. JCA (Java Connector Architecture) see http://code.google.com/p/jca-sockets/ for a example

  2. The JBOSS Netty Project

I recently create a tcp/ip server in Apache Camel and it was very easy.

like image 54
Namphibian Avatar answered Sep 06 '26 21:09

Namphibian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!