Sign in to follow this  
tmack

C# 2.0 Sockets -- Network programming ques

Recommended Posts

I have a few questions about network programming. I do have experience in network programming, it's limited but I understand the concept of how TCP and UDP work. I have designed a few peices of small software (testing) that uses both TCP and UDP-- so yes, I understand the concept. First off, I'm using C# 2.0. I have plenty of experience in C#... but I never used anything networking-related to C# or .NET for that matter. I'm planning to design a full-scaled networking code in C# for use in all of the software I create (it won't be free avaliable). So it has to be scalable, of course. The most important thing is it MUST be fast to use, also it must use the least possible memory as possible. The code will be used in multiplayer games (at least handling 200 players at a time, if not more!), instant messaging software, voice chat software (like Teamspeak/Ventrilo), video streaming, updating/downloading software, etc. The most important is that it can work in the game I'm developing. So... here's my questions. 1. Should the server be multithreaded? This is a lot harder, but can pay off-- is it worth it? *Note: The server for the game will ahve to load maps, scripts (npcs), etc.. so is it almost required? 2. Use low-level "sockets" or use the built in "TCPClient", "TCPListener", "UDPClient"? 3. For the game, should I use strictly UDP or TCP? I've had people tell me to use UDP for movement/game related, and TCP for chatting/etc. I prefer UDP. My game will be a 2D MMORPG with NPCs and other things. I can't think of anything else at the moment-- long day at work. If someone could answer my three questions, I'd apperciate it.

Share this post


Link to post
Share on other sites
Check out the Forum FAQ about threading. In brief, you want to do overlapped I/O on sockets for best performance in Windows. Over-threading will hurt you.

Also, for all of those applications you're talking about, the optimal networking solution is very different. Video streaming looks almost nothing at all like an instant messaging service. I would pick one target, and code for that first. Then, as I needed new targets, I'd look at doing a new module for that new target, re-using only the parts that make sense from the previous module.

Share this post


Link to post
Share on other sites
Thanks-- the most important thing I need to know if should use SOCKETS or TCPClient/TCPListener (and the UDP ones)?

Is TCPClient more limited then using regular sockets?

Share this post


Link to post
Share on other sites
I built a scalable server architecture in C# awhile ago and used the base sockets library. IOCP with the .NET framework is dead simple compared to unmanaged C++ in my opinion, and there is no reason not to use it.

Share this post


Link to post
Share on other sites
I think .Net's asynchronous sockets (look it up in the help or MSDN) are designed to be scalable, so I recommend you just use those. The TCPClient and friends are relatively thin covers on the Socket class anyway, so use whichever you're more comfortable with.

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