After two weeks of getting STUNned, finally managed to let 2 port restricted NATs talk to each other!
For the uninitiated, STUN (Simple Traversal of UDP through NATs), is a protocol to discover information about a client which is trying to connect to a server using UDP. Coding up the STUN server (a very ultra basic one) wasn't extremely difficult, after using the API from jStun, sadly they didn't have server code =p.
The hard part however, was getting the clients to talk to each other. Went through a major refactor early in the stage of development as I was sending really messy datagrams to the server, either a discovery object or strings. Really bad. So I looked at it, and refactored everything to send serialised packets of a special datatype which I defined.
Once that was firmed up, it was time for P2P! .. The concept isn't hard, simply send UDP packets from client A to client B (and vice versa) until the NAT opens up but in practise mine never happened <_< I even ran Wireshark to look but it didn't seem to be responding properly =\
Finally today! Managed to do it, right now server communication and client - client communication are using the same port though, not what I envisioned earlier, but if it works, it works huh.
Still extremely raw and buggy though, as I said, it's raw-er than sashimi .. but it works!
RAWR!
wow! you are amazing! congrats!! :D
ReplyDelete-yj