Socket.BeginAccept和异步操作

编程入门 行业动态 更新时间:2024-10-27 21:23:17
本文介绍了Socket.BeginAccept和异步操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想了解一下我使用套接字类的BeginAccept方法会发生什么.当您使用BeginAccept时会发生什么?系统是否使用ThreadPool线程来处理对新连接的接受,然后使用IAsyncResult向执行线程发送消息?还是ThreadPool线程是执行AcceptCallback方法的线程? 我正在尝试制作一个Asynchronus MultiThreaded Server Application.我有25个线程是后台线程,我想用它们来激发客户端连接并处理接收到的数据.但是我不明白如何将MultiThreading与Asynchronus套接字结合使用. 当我调用BeginSomething时,当代码转到CallBack方法时,它会杀死单独创建的线程吗?还是系统只是用IAsyncResult信号通知正在执行的线程而已,并且主应用程序线程正在执行数据处理? 如果是这种情况,是否意味着我必须以某种方式指示我的应用程序中有25个线程在一个循环中执行BeginRecive?我的服务器处理许多连接,每个套接字都添加到队列中. 我在哪里使用25个线程来提高速度和可伸缩性?还是我不需要创建25个线程,并且套接字的异步操作将意味着我默认情况下隐式使用多线程,并且当我调用BeginSomething时,系统线程将执行CallBack方法吗? 我还需要循环调用BeginRecieve吗?还是一旦我在套接字中调用BeginRecive,就意味着有一个正在轮询客户端数据的线程,除非我停止服务器进程,否则它将永远不会停止?还是在我转到回调方法并调用EndRecieve时结束?

HI guys,I am trying to understand what happens when i use the BeginAccept Method of the socket class.When you use BeginAccept what is actually happens? Does the system uses the ThreadPool threads to process the acceptance of a new connection, and then sends a message to the executing thread with an IAsyncResult? or that the ThreadPool thread is the one that executes the AcceptCallback method?I am trying to make an Asynchronus MultiThreaded Server Application. I have 25 threads that are background threads, and I want to use them to provoke the client connections and process data recived. But i dont understand how to marry MultiThreading with Asynchronus sockets. When i call BeginSomething, when the code goes to the CallBack method, does it Kill the thread that was created seperately? or does the system just signal the executing thread with the IAsyncResult and that is it and the main application thread is what is going the data processing?If this is the case, does that mean i have to somehow instruct the 25 threads in my application to execute the BeginRecive in a loop? my server handles many connections and each socket is added to a Queue.Where do i use the 25 threads to improve speed and scalability? Or do i not need to create 25 threads, and asynchronus operations of the socket would mean that i am implicitly using multi-threading by default, and that when i call BeginSomething the system thread will execute the CallBack method?Also do I need to call BeginRecieve in a loop? or once i call BeginRecive in a socket, it means that there is a thread that is polling for client data and will never get stopped unless i stop the server process? or does it end once i go to the callback method and call EndRecieve? which means that you have to recall BeginRecieve in a loop?Anyhelp would be appreciated!

推荐答案

Voldemort先生!您找到这个问题的答案了吗?我陷入了和你一样的处境.如果可以的话,您能为我回答吗?我会很感激的. Hi Mr. Voldemort! Have you found any answers to this question? I am falling into the same situation as you did. Could you answer it for me if possible? I will Appreciate that.

更多推荐

Socket.BeginAccept和异步操作

本文发布于:2023-10-30 03:00:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541566.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作   Socket   BeginAccept

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!