UDP Handshaker server (app) needed to handle NAT problems - any help?

Recommended Posts

I've gone through the forum FAQ about dealing with NAT, and friend of mine gave me a really good resource about NAT/punching holes: http://www.brynosaurus.com/pub/net/p2pnat/ (especially part 3.4) I'm using UDP to handle traffic, so I need some kind of script to listen to UDP packets. I have a dedicated unix server that I can use... and I'm using an UDP library (Blitz3D + BlitzPlay). I pretty much have lots of stuff to use, but I don't know how to create that piece of software which would handle that UDP handshake? Since my problem is quite common in the gaming area, I thought *somebody* must have done a script. I would even be willing to pay some \$ just to get the system done. Any help on this?

Share on other sites
I'm going to assume that you already have some mechanism to find other users to connect to, and that all your trying to do is prepare the route for direct peer-to-peer.

The simplest thing to do would be to write a daemon that listens on a specific UDP port. For every packet that it receives, send a reply back that contains the port that that packet was received on. Now you can send that information to the other peer.

Here is the meat of a daemon I wrote to do just that.
        while (1)        {                FD_ZERO (&Fds);                FD_SET (sUdp, &Fds);                ret = select (sUdp+1, &Fds, NULL, NULL, NULL);                if (ret)                {                        if (FD_ISSET (sUdp, &Fds))                        {                                Len = sizeof(struct sockaddr);                                ret = recvfrom (sUdp, Buffer, BUFFER_SIZE, 0, (struct sockaddr *)&SrcAddr, &Len);                                if (Buffer[0] == 0x72)                                {                                        *(unsigned short *)(Buffer+2) = SrcAddr.sin_port;                                        ret = sendto (sUdp, Buffer, 4, 0, (struct sockaddr *)&SrcAddr, sizeof(struct sockaddr));                                        if (!Daemonize) printf ("PKT_KEEPALIVE: Ip: %s Port: %d\n", inet_ntoa (SrcAddr.sin_addr), ntohs (SrcAddr.sin_port));                                }                        }                }        }

--Zims

Share on other sites
Programming Gems 5 has an article about that, as well as source code I believe. Since it's rather application dependant, and not 'that' hard to do, you might as well do it yourself. You will probably need to setup some sort of introducer / service that allow for matchmaking, sessions and NAT punchthrough.

Share on other sites
Yes, I was going to recommend my article in GPG 5 as well :-)

However, it's not enough to "do introduction" -- you have to know WHO you want to introduce to, and they have to know you as well. That, in turn, falls into the matchmaking realm, which turns into a lobby server mechanism, which is not entirely trivial. It's also often fairly game specific, although there are lobby services available as middleware (such as GameSpy).

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

• Partner Spotlight

• Forum Statistics

• Total Topics
627652
• Total Posts
2978424

• 10
• 12
• 22
• 13
• 33