AsyncUserToken class is missing in SocketAsyncEventArgs sample: How to make the sample works?

允我心安 提交于 2020-05-29 03:28:24

问题


I am working on TCP multithread server and client. I found some codes from Microsoft websites: http://msdn.microsoft.com/en-us/library/system.net.sockets.socketasynceventargs.aspx

However I got the following error:

The type or namespace name 'AsyncUserToken' could not be found (are you missing a using directive or an assembly reference?)

I cant find what namespace to include even I searched it on Google, here are those I currently have:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;

Thanks for help.


回答1:


The AsyncUserToken class is not part of the .NET framework. It looks like it has been forgotten in the Microsoft sample.

You can create yourself the AsyncUserToken class with a Socket property (corresponding to the socket used to perform the I/O operations) :

internal class AsyncUserToken
{
  public System.Net.Sockets.Socket Socket { get; set; }
}



回答2:


Well, I guess I found something related: http://www.codeproject.com/Articles/22918/How-To-Use-the-SocketAsyncEventArgs-Class



来源:https://stackoverflow.com/questions/15738062/asyncusertoken-class-is-missing-in-socketasynceventargs-sample-how-to-make-the

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!