0

In Stefen Toub's code Awaiting Socket Operations : it doesn't mention about the usage of its async methods. I mean how the Server program will be calling the async methods using await? Ther isn't any main() also. Please elaborate over this. I tried creating a main() and calling the SocketExtensions.ReceiveAsync(sock,awaitable);

public static void Main(string[] str)
{
    Console.WriteLine("\n\n<<<<<<<<<<<  Server is starting...  >>>>>>>>>>>>>>>>>");

    IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10100);
    Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    var args = new SocketAsyncEventArgs();
    args.SetBuffer(new byte[0x100000], 0, 0x100000);
    var awaitable = new SocketAwaitable(args);
    while(true)
        SocketExtensions.ReceiveAsync(sock,awaitable);
}

But it didn't work for me.

1
  • 2
    What exactly 'didn't work'? Commented Oct 28, 2013 at 10:32

1 Answer 1

4

Stephen Toub's blog post is not a sockets tutorial; it's showing how to use custom awaitables to support extremely high-performance socket applications.

I recommend that you start with something like WebAPI or WCF and only use bare sockets if you have to. If you absolutely do need to use sockets, then I recommend that you first use TaskFactory.FromAsync to wrap the Begin/End methods; this is slightly less efficient but an easier programming model. If performance tests indicate that your server isn't fast enough at this point, then you should use the custom awaiter approach from Stephen Toub's blog post.

The reason your server isn't working is because you're not listening nor accepting. I recommend you use WebAPI or WCF instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.