Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[C#][Help] Multiuser Async Sockets

Ask me about Daoism
Loyal Member
Joined
Nov 6, 2010
Messages
1,560
Reaction score
393
Hello /f(12^2)/!

I need some halp.

I've entered a new chapter of socket usage in C#, where I'm now writing servers. I have two critical questions though.

1. People say Async sockets don't hold up the calling thread. Does this mean this is a required feature if I'm to have multiple users active while the server is operating? If not, where will async come into play?

2. This: seems like a good place to start for me, but it's multithreaded. This is fine, but how does this differ from asynchronous sockets? And is it stable? From what I understand in the 2 mins spent speed-reading it (class soon), I think it creates a separate thread for each user.

Also, if anyone can point me to a good guide, explanation, or example, it would be much appreciated.
 
Banned
Banned
Joined
Apr 23, 2015
Messages
28
Reaction score
0
as far as i know [h=1]Asynchronous (Async)[/h]Is called only if you use NET 4 and HIGHER in Visual Studio 2012 and above the purpose of this is to can avoid performance bottlenecks and enhance the overall responsiveness of your application by using asynchronous programming

for example:
Code:
[COLOR=#ff0000]async [/COLOR]Task<[COLOR=Blue]int[/COLOR]> AccessTheWebAsync()
{ 
    [COLOR=Green]// You need to add a reference to System.Net.Http to declare client.[/COLOR]
    HttpClient client = [COLOR=Blue]new[/COLOR] HttpClient();

    [COLOR=Green]// GetStringAsync returns a Task<string>. That means that when you await the [/COLOR]
    [COLOR=Green]// task you'll get a string (urlContents).[/COLOR]
    Task<[COLOR=Blue]string[/COLOR]> getStringTask = client.GetStringAsync([COLOR=#A31515]"http://msdn.microsoft.com"[/COLOR]);

    [COLOR=Green]// You can do work here that doesn't rely on the string from GetStringAsync.[/COLOR]
    DoIndependentWork();

    [COLOR=Green]// The await operator suspends AccessTheWebAsync. [/COLOR]
    [COLOR=Green]//  - AccessTheWebAsync can't continue until getStringTask is complete. [/COLOR]
    [COLOR=Green]//  - Meanwhile, control returns to the caller of AccessTheWebAsync. [/COLOR]
    [COLOR=Green]//  - Control resumes here when getStringTask is complete.  [/COLOR]
    [COLOR=Green]//  - The await operator then retrieves the string result from getStringTask. [/COLOR]
    [COLOR=Blue]string[/COLOR] urlContents = [PHP]await [/PHP]getStringTask;

    [COLOR=Green]// The return statement specifies an integer result. [/COLOR]
    [COLOR=Green]// Any methods that are awaiting AccessTheWebAsync retrieve the length value. [/COLOR]
    [COLOR=Blue]return[/COLOR] urlContents.Length;
}

FullmetalPride - [C#][Help] Multiuser Async Sockets - RaGEZONE Forums
 
Back
Top