Skip to main content
GameDev.net gamedev.net
🔒 Locked

C# Select (non-blocking) tutorial?

Started by nPawn Jul 6, 2006 at 4:34 PM 4 replies 1.5k views
Original Post
nPawn
nPawn
Anyone know of a tutorial for C# that discusses non-blocking via the Select function (instead of the Asynchronous method which i've read is a bad idea for games that send a lot of data). Seems there are plenty of asynchronous tutorials out there but i'm having a hard time finding one that uses Select non-blocking. Edit: Now i'm wondering if I should in fact go with asynchronous networking. This MSDN article: http://msdn.microsoft.com/msdnmag/issues/05/08/HighPerformanceSockets/default.aspx claims that asynchronous is the best mode to use, and NET 2.0 has some handy network logging available. I'm still a bit skeptical though, because doesn't asynchronous mode use the windows message pump? And it seems like that would get easily clogged if I was pushing a lot of packets through..? [Edited by - nPawn on July 6, 2006 5:03:25 PM]
hplus0603
hplus0603
Asynchronous sockets are what you get when you call WSAAsyncSelect(), and it posts messages to your main message loop. Performance is awful.

That article is confusing, because it's talking about "asynchronous I/O" within the context of the .NET framework -- which is really implemented using I/O completion ports and overlapped I/O.

Remember: "Asynchronous I/O" != "Asynchronous Sockets".

Using the .NET sockets in asynchronous mode (based on I/O completion) is fine for performance and games.
enum Bool { True, False, FileNotFound };
Telastyn
Telastyn
C#/.NET select will behave just like the general BSD style select() except that it replaces FDSETs with standard .NET enumerables, and ignores the traditional first parameter. Thus any common tutorial for select() (such as Beej's) will be fine to learn from; remembering the slight changes. I have some code floating around somewhere that uses it if you still run accross problems.
Washu
Washu
I don't see what's confusing about that article, but anyways: Asynchronous I/O is implemented using I/O completion ports (when available), but that is certainly not guaranteed (and ealier versions of the framework didn't use IOCP in certain classes).

As far as Socket.Select goes, it uses the traditional select() function to perform its work.

Performance wise, asynchronous functions (Begin/End) will beat out select hands down if you need a great many sockets. Two things though: first of all, you will have two design around that functionality. The traditional approaches just don't work with Async I/O. Secondly, the performance gains for a small number of sockets is negligable at best, and the design requirements may cause you some headaches unless you have experience with threading/IOCP.
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
hplus0603
hplus0603
The confusion is that nPawn confused "asynchronous I/O" with "asynchronous sockets" which are not the same thing.

In fact, what most people call "asynchronous I/O" is, technically, called overlapped I/O on Windows kernels, so the article is confusing by not using the underlying terminology.

Again: "asynchronous sockets" != "asynchronous I/O".

Also, "asynchronous sockets" != "asynchronous (overlapped) I/O on sockets".
enum Bool { True, False, FileNotFound };
nPawn
nPawn
Thanks for the clarification!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.