简体   繁体   中英

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...");

----------

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM