编写监听端口的Openfire插件

 

 

最近需要写一个openfire插件,需要监听某个端口(以UDP协议传输的),按照照普通的方式(线程+DatagramSocket),写好之后,服务器端不再监听 5222/5223等端口了……,没查到什么解决方法,后来看了看Red5的源码,发现他的实现方式是用了mina,就换成了mina方式,打包上传,OK,成功了……

代码如下

 
 public void destroyPlugin() { System.out.println("unloading " + pluginName + " plugin resources"); acceptor.unbind(new InetSocketAddress(listenPort)); acceptor = null; } private String pluginName = "ipport"; private int listenPort = 1585; private UDPServer udpServer; private DatagramAcceptor acceptor; public void initializePlugin(PluginManager manager, File pluginDirectory) { System.out.println("~~~~~ Init ip port plugin ~~~~~~~"); IoAcceptor acceptor = new DatagramAcceptor(); IoAcceptorConfig config = new DatagramAcceptorConfig(); DefaultIoFilterChainBuilder chain = config.getFilterChain(); //Use text codec, Client send string which shoudl end with "/r/n" or "/n" to server. chain.addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory())); try { acceptor.bind(new InetSocketAddress(listenPort), new DatagramHandler(), config); //DatagramHandler extends IoHandlerAdapter log.info("IpPort is listening port " + listenPort ); } catch (IOException e) { e.printStackTrace(); } }

关于 mina的一些资料,google一下就有很多

下面的可以看看

Welcome to Apache MINA Project!
http://mina.apache.org/

使用 Apache MINA 开发高性能网络应用
http://www.ibm.com/developerworks/cn/opensource/os-cn-apmina/

利用MINA传送对象,字符串(前后台代码)
http://blog.csdn.net/heyi1214/archive/2009/05/27/4221141.aspx

 

 

转载请注明:Http://blog.csdn.net/laorer

你可能感兴趣的:(apache,String,网络应用,Mina,resources,Codec)