Sign in to follow this  
dadads

Binding and UDP

Recommended Posts

Hi all, While recently tinkering around with C#'s Socket class, I have just found out that I could broadcast/receive packets without having to bind/connect my UDP sockets at all. How does this work? By the way, where can I find a C++/C#/VB.NET tutorial for using UDP sockets? Thanks alot, - dadads -

Share this post


Link to post
Share on other sites
UDP is connectionless. When you send stuff via UDP, you just spray your packets into the void and hope they arrive where you aimed them, and they usually do arrive just fine. Establishing a connection with a socket for use with UDP isn't necessary, and doesn't add any extra functionality or reliability. All it does is tells the system that you want that particular socket to always point it's data at a given location, so you don't have to specify it with every send. In all seriousness, it's not needed, and is largely limiting [since one of the nice things about UDP is being able to use 1 socket to recieve from and send to a lot of different places]

Anyway, Beej gives a pretty good once-over for socket programming in C. It's Unix specific though, and windows' WinSock has a few little quirks that you need to take care of first [like WSAStartup(), among a very few others]. *Nearly* everything in beej's guide is platform independant though. It's also well written, to the point, and assumes you have absolutely no knowledge of anything that it is covering [which means it's good for learning]. It also covers the theory side, so you'll get an understanding that will be carriable across languages. [it's all in C, and uses straight berkeley sockets]

Your documentation [or msdn.com, if you're not using MSVS] will also provide you with elaboration on specific functions, and fill in the blanks with regard to porting the networking code to windows.

On the topic of windows, I hear [though I have no experience with it] that C# makes working with I/O Completion ports a lot easier than it is in c++ [It's rather nasty in c++]. I/O Completion ports are *THE* way to go if you want high-performance network code on a windows machine. They are more complicated, so it is advised that you shoot for regular 'vanilla' sockets first, but it's something to keep in mind for the future.

Share this post


Link to post
Share on other sites

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

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this