powered by Jive Software

How to write a plugin which listen a port with udp

I want to write a plugin which listen a port with udp, but when I code it as normal( a thread and a udp socket), update it to plugins directory, and restart openfire, the openfire does not listen to port 5222 and 5223,

I don’t know what should I do, maybe there is an API about socket. I find classes like SocketAcceptor and ConntectionManagerImp, but I’m not sure how to use them.

Thanks…

BTW:

I want to write a soft to talk p2p, but I don’t know how to get public ip within nat, so I write a plugin to get public ip and port and send them back.

You’re welcom to give me another solution.

Thanks a lot

There is usually no public IP inside the LAN behind a NAT.

You post sounds like you’re trying to do UDP hole punching, which can be done with a STUN server or a DHT (see azureus source for details). Keep in mind that the DHT approach has bootstrapping problem.

Thanks for your reply!

Yes, I want to do UDP hole puching, like UDP hole punching Algorithm(http://en.wikipedia.org/wiki/UDP_hole_punching#Algorithm

). Now I need to do first step, getting temporary external port numbers, and my plugin is used to listen these connection. But when I listen on a port like 9945 , Openfire does not listen on 5222/5223. Do you have some solutions?

Thanks again for your help!

Now, I found that in openfire plugin, you should used org.apache.mina.transport.socket.nio.DatagramAcceptor (http://mina.apache.org/)to listen port with udp, and implement IOHandler to do something.


But I don’t exchang message with external ip and port,in another word, I failed to hole punch.

A --|NATa --------Server------------- NATb|–B
A and B get external ip:port theirself(ip:port of NATa and NATb), and exchange external ip:port, then send message to partner’s external ip:port, but it failed.

I don’t know the type of the NATa and NATb, I get it with stun protocal, but returns udpblock

Any suggestions?