在Apache Tomcat上运行的Java TCP服务器程序 [英] Java TCP server program running on Apache Tomcat

查看:153
本文介绍了在Apache Tomcat上运行的Java TCP服务器程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我有一些问题,TCP服务器程序,
我创建了是有TCP服务器code和这需要连续运行一个罐子,我需要部署这个jar在Apache服务器...
这个罐子当我们执行命令,从它的运行的Apache Tomcat的时候提示ANS将不接受传入连接的罐子工作正常,在Apache中我已经有些罐子运行,所以他们并不依赖于这个罐子。

 ,而(真){
    客户端的Socket的ServerSocket.accept =();
    的System.out.println(S:接收...);----------


解决方案

我们在几年前这样做成功地为一个聊天程序,但它是保持一个噩梦。这样做有几个其他更加规范的方式。从我这里头的顶部是我们所做的事情。


  1. 创建一个servlet

  2. 在servlet的init函数创建的服务插座一个线程。

您可以在这里看到这样一个例子连接到插座上的Tomcat?。也看过这个讨论<一个href=\"http://stackoverflow.com/questions/2417930/how-to-listen-a-socket-in-tomcatservlet-container\">How监听套接字在Tomcat中(servlet容器)?

一些替代品将是谷歌以下内容:


  1. JCA(Java连接器架构)请参见的http:// code.google.com / p / JCA的插座/ 一个例子


  2. 在JBoss的Netty项目


我最近创建Apache的骆驼一个TCP / IP的服务器,这是非常容易的。

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.

这篇关于在Apache Tomcat上运行的Java TCP服务器程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆