BS架构满天飞,对这种接j2ee服务器的CS程序好像没人关心了,自己顶

解决方案 »

  1.   

    问题一:用Socket监听端口
    其他的我也不太了解
      

  2.   

    数据通讯可以使用2种方式。一种是rmi的方式。一种是socket方式
    2种方式各有优点和缺点
      

  3.   

    其实用ejb不是一个好得选择。
    远程访问ejb就是非常耗时得一件工程。
    ^_^
      

  4.   

    socket方式可能会因为放火墙的原因出现问题。你可以参看
    http://www.javaworld.com/javaworld/jw-12-1997/jw-12-step.html
    这篇文章。里面讲了2种方式的特点和实现方式及相关代码。
      

  5.   

    Socket-based 
    The socket-based implementation enforces strict lock-step among the clients by relaying all updates to the central display through the server. The advantage of this technique is that updates to the list are displayed in real-time by the clients. The disadvantage is that all clients require a direct TCP/IP connection to the server, which may not be possible in an environment with firewalls and other constraints. Our use of object streams to encapsulate messages provides us with a much cleaner interface than using raw bits and bytes; however, there is still some effort required to implement a multithreaded server that can handle network failures, among other potential disasters. RMI-based 
    The RMI-based environment, on the other hand, allows clients to proceed on their merry way independent of the central list. If a client makes an update to the list, the server will inform it whether or not the update was approved; however, the server will not tell the client what other changes have been made (although it could). Instead, it is up to each client to regularly poll the server -- either manually or automatically -- for updates from other clients. RMI usually requires a direct socket connection to the central server, but it also has support for HTTP proxying of requests should that be necessary. As a result, our RMI-networked whiteboard can operate behind a firewall where HTTP traffic is permitted or proxied. For this particular application, the socket-based solution is, in general, superior. RMI, however, has the advantage of being fairly simple, and in an environment where real-time update is not a necessity, an RMI-based distributed list is far more elegant than the socket-based approach. Note that our RMI list has no knowledge of when clients connect or disconnect, of threads, or of network failures; it must simply respond to method calls that are made by the RMI substructure. For real-time updates, however, the overhead of clients constantly setting up network connections to poll the server is most undesirable. An alternative to RMI with polling would be to implement a thoroughly RMI-based ObservableList. Updates from clients would be made through RMI calls to the server, and these updates would then result in the server making RMI calls back to all the registered listeners -- no matter where on the network they are. Although interesting in concept, this approach has a few failings: Unlike our current RListImpl, the RMI-based server would have to maintain a list of all active clients, making the solution less elegant. Furthermore, and this is what makes this approach useless to our applet-based whiteboard, the clients would then have to expose themselves as remote objects that could be accessed by the server. This goes against the security model imposed by most browsers, and, thus, would require that the clients be digitally signed and trusted by the users -- an undesirable burden.
      

  6.   

    搞这么多东东干啥,用http+xml+servlet+javabean+jdbc不就行了。至于server向client发消息。在client搞个httpServer就行了。这类的控件大把啦
      

  7.   

    也就是说socket要受tcp/ip限制。而rmi可以通过http。但是socket是时时的。而rmi不是。
      

  8.   

    hehe,听了上面高人的指点,不甚感激。
    其实现在用j2ee,大多是做BS的程序,很多底层的实现都已经有人做好了,包括通过防火墙,向客户端发消息等,都有固定的模式或者类库。但我现在做的因为是面向电信的告警系统,很多东西还不能在web上灵活表示,当然我会考虑移植到web上,但就程序来说,很多都已经实现了,就是复杂了些,效果不是很好。rmi的调用是非连接的(我认为),每次方法的调用都要创建连接,类似webservice,如果做北向接口,倒是很合适,对于我的程序来说,肯定要有稳定的连接,包括断线重联机制,所以考虑还是要原始的socket.其实rmi也是基于socket之上的类库,就不能说rmi能过防火墙,socket不能的。其实现在能通过防火墙,一般都是使用http协议,http也是基于tcpip的,也是socket通讯。如果我把socket写成http隧道,还是可以实现这个功能的,这个我不说了。
    搞这么多东东干啥,用http+xml+servlet+javabean+jdbc不就行了。至于server向client发消息。在client搞个httpServer就行了。
    =========
    老兄,我的是应用程序,这样也太麻烦了把。再次感谢以上各位,再看看还有高见
      

  9.   

    Socket嘛,我觉得如果担心防火墙的问题,那通讯的东东都不要做了吧
      

  10.   

    http+xml+servlet+javabean+jdbc复杂吗?随便哪个jsp网站都用到了吧。可能内容不走xml。但客户端的很多控件都支持xml的,不用可惜了。你自己实现http协议?太酷了点吧,你不用考虑稳定的吗
      

  11.   

    hehe,楼上的,说实话,我觉得http+xml+servlet+javabean+jdbc这一套的东西太简单了点,对一些大型的应用可能还不是很适用。数据走xml,有点太浪费带宽了,当然有二进制xml,但还是有解析xml的过程,所以我认为如果不是很公用,异构的程序,根本可以不用xml做传输。http,servlet,jdbc还都是简单web的内容,而且还有点原始的感觉。对一些大型的,分布式的系统,不是简单的用一个数据库和一个tomcat就可以解决的。当然,我说的并不是实现http协议,只是想基于基本的socket,来实现稳定的数据传输方式。
    防火墙,根本不是我考虑的重点,或者根本不是问题,因为我的程序肯定是通过用户的校验的,不是偷偷运行的,如上面一位老兄说的,“我觉得如果担心防火墙的问题,那通讯的东东都不要做了吧”。
    不过还是很感谢这位老兄,有机会的话,可以和你探讨探讨。
      

  12.   

    我觉得http+xml+servlet+javabean+jdbc也是个不错的选择,毕竟xml是一个平台无关的好东西啊
    如果楼主觉得传输xml和解析xml太消耗资源的话,再如果只是传输一些简单的文本数据,那就可以自己定义一个数据格式,这样不用xml,解析也会更容易
      

  13.   

    对于java程序的数据传输,在服务器和客户端都是java的时候,对象序列化是很好的选择
      

  14.   

    我是这样设计的:
    application实现socketServer,然后用它去调用同一个jvm的ejb,通过session bean来调entity bean来实现整个客户端与服务器的通讯。上面一位兄弟说到,在客户端使用servlet,那就必须需一个固定IP地址,这对大量的c/s开发,是不可取的。个人愚见:)
      

  15.   

    sjcode(愚者) 说的不错,大体是我现在的思想。
    不过,怎么在一个虚拟机里调用ejb,还是有点疑惑。比如weblogic,在startup里实现。我不是不想这样做,我是怕真正运行的时候可能会有一些问题。我现在是单独一个应用程序,调用ejb的接口,其实好像就是个客户端的代理。谢了sjcode(愚者)。
      

  16.   

    分我全都给了,平均下来,每条发言都是10分,不知道为什么,在这里还是看不到给的分数,我在管理页面可以看到。tnnd的csdn.