Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Socket.SendAsync参数错误_C#_Sockets - Fatal编程技术网

C# Socket.SendAsync参数错误

C# Socket.SendAsync参数错误,c#,sockets,C#,Sockets,我目前正在学习ASP.NET MVC,遇到了一个问题。在我正在学习的课程中,他们使用了来自Socket类的方法-sendaync,但当我尝试使用它时,它只要求一个SocketAsyncEventArgs类型的参数,而在课程中,它要求两个参数-一个ArraySegment和一个SocketFlagEnum。这怎么可能?我的项目的目标是.NETFramework 4.6.1 public class ConnectionHandler { private readonly Socket cl

我目前正在学习ASP.NET MVC,遇到了一个问题。在我正在学习的课程中,他们使用了来自
Socket
类的方法-
sendaync
,但当我尝试使用它时,它只要求一个
SocketAsyncEventArgs
类型的参数,而在课程中,它要求两个参数-一个
ArraySegment
和一个
SocketFlag
Enum
。这怎么可能?我的项目的目标是.NETFramework 4.6.1

public class ConnectionHandler
{
    private readonly Socket client;

    private readonly IServerRouteConfig serverRouteConfig;

    public ConnectionHandler(Socket client, IServerRouteConfig serverRouteConfig)
    {
        this.client = client;
        this.serverRouteConfig = serverRouteConfig;
    }

    public async Task ProcessRequestAsync()
    {
        string request = await this.ReadRequest();

        IHttpContext context = new HttpContext(request);

        IHttpResponse response = new HttpHandler(this.serverRouteConfig).Handle(context);

        ArraySegment<byte> toBytes = new ArraySegment<byte>(Encoding.ASCII.GetBytes(response.Response));

        await this.client.SendAsync(toBytes, SocketFlags.None);

        Console.WriteLine(request);
        Console.WriteLine(response.Response);

        this.client.Shutdown(SocketShutdown.Both);
    }
公共类ConnectionHandler
{
私有只读套接字客户端;
专用读卡器VerRouteConfig服务器RouteConfig;
公共连接处理程序(套接字客户端、IServerRouteConfig服务器RouteConfig)
{
this.client=client;
this.serverRouteConfig=serverRouteConfig;
}
公共异步任务ProcessRequestAsync()
{
string request=等待这个。ReadRequest();
IHttpContext context=新的HttpContext(请求);
IHttpResponse response=newHttpHandler(this.serverRouteConfig.Handle)(上下文);
ArraySegment toBytes=新的ArraySegment(Encoding.ASCII.GetBytes(response.response));
等待这个.client.sendaync(toBytes,SocketFlags.None);
控制台写入线(请求);
Console.WriteLine(response.response);
this.client.Shutdown(SocketShutdown.Both);
}
SendAsync
方法诞生于
.NET Framework v3.5
,其语法从未改变:

public bool SendAsync(SocketAsyncEventArgs e)
所以:要么讲座是错误的,要么它不是指
Socket
类的
SendAsync
方法

但是,如果查看
Send
方法

public int Send(IList缓冲区、SocketFlags和SocketFlags)

为什么不问问为你提供讲座的人呢?原来我的项目必须是.NET核心项目,而不是.NET Framework项目。谢谢你的帮助。
public int Send(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags)