简体   繁体   English

在Apache Tomcat上运行的Java TCP服务器程序

[英]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. 这里我有一些TCP服务器程序的问题,我已经创建了一个具有TCP服务器代码的jar,这需要连续运行,我需要在apache服务器中部署这个jar ...这个jar在我们执行时工作正常来自命令提示符ans的jar在运行apache tomcat时不会接受传入连接,在apache中我已经运行了一些jar,所以它们根本不依赖于这个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 创建了一个servlet
  2. In the servlet init function created a thread that services the socket. 在servlet init函数中创建了一个为套接字提供服务的线程。

You can see a example of this here Connecting to socket on Tomcat? 你可以在这里看到这个连接到Tomcat上的套接字的例子吗? . Also read this discussion How to listen a socket in Tomcat(servlet container)? 另请阅读本讨论如何在Tomcat(servlet容器)中监听套接字?

Some alternatives would be to google the following: 一些替代方案是谷歌以下:

  1. JCA (Java Connector Architecture) see http://code.google.com/p/jca-sockets/ for a example JCA(Java Connector Architecture)有关示例,请参阅http://code.google.com/p/jca-sockets/

  2. The JBOSS Netty Project JBOSS网络项目

I recently create a tcp/ip server in Apache Camel and it was very easy. 我最近在Apache Camel中创建了一个tcp / ip服务器,非常简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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