SocketAsyncEventArgs示例中缺少AsyncUserToken类:如何使该示例起作用? [英] AsyncUserToken class is missing in SocketAsyncEventArgs sample: How to make the sample works?

查看:90
本文介绍了SocketAsyncEventArgs示例中缺少AsyncUserToken类:如何使该示例起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TCP多线程服务器和客户端.我从Microsoft网站上找到了一些代码: http://msdn.microsoft.com/en-us/library/system.net.sockets.socketasynceventargs.aspx

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

但是我遇到以下错误:

找不到类型或名称空间名称"AsyncUserToken"(是您缺少using指令或程序集引用吗?)

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

即使我在Google上搜索过,我也找不到要包含的名称空间,这是我目前拥有的名称空间:

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;

感谢您的帮助.

推荐答案

AsyncUserToken 不属于.NET框架.看来它已经在 Microsoft示例中被忘记了.

您可以使用 Socket 属性(对应于用于执行I/O操作的套接字)来创建 AsyncUserToken 类:

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; }
}

这篇关于SocketAsyncEventArgs示例中缺少AsyncUserToken类:如何使该示例起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆