.NET中的异步套接字编程 [英] Async socket programming in .NET

查看:79
本文介绍了.NET中的异步套接字编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我编写了从证券交易所异步接收数据的程序,然后将其发送给当时连接的所有客户。这些数据是从数据包交换中连续接收的,这些数据包立即发送给客户端。我面临的问题是,有大的没有。连接的客户端(大约1000个)以及当我收到任何数据包时尝试发送给所有这些客户,有一个时间延迟。也就是说,一些客户端首先接收数据然后等待,而某些客户端在延迟之后接收数据。我使用以下循环发送数据。

for int i = 0; i< m_workerSocketList.Count; i ++)

Hi

I have written program to receive data asynchronously from stock exchange and then send it to all the clients who are connected at that time. This data is received continuously from exchange in packets and these packets are sent to the clients immediately. The problem I am facing is, there are large no. of clients connected (about 1000) and when I receive any packet & try to send to all these clients, there is a time delay. That is, some clients receive data first and then it waits, where as some clients receive data after a lag. I am sending the data using following loop.

for (int i = 0; i < m_workerSocketList.Count; i++)

{

if (m_workerSocketList [i]!= null

    if (m_workerSocketList[i] != null)

{

套接字 workerSocket =( 套接字 )m_workerSocketList [i];

        Socket workerSocket = (Socket)m_workerSocketList[i];

if (workerSocket.Connected)

        if (workerSocket.Connected)

{

workerSocket.Send(headerData,0,11, SocketFlags .None);

            workerSocket.Send(headerData, 0, 11, SocketFlags.None);

workerSocket.Send(theSo ckId.dataBuffer,0,nWaitForDataLen, SocketFlags .None);

            workerSocket.Send(theSockId.dataBuffer, 0, nWaitForDataLen, SocketFlags.None);

}

}

}

有人可以帮助我没有任何延迟地完成工作?

感谢

Vivek

Can somebody help me to do the job without any delay ?

Thanks

Vivek

推荐答案

你会想要使用异步发送(例如,BeginSend)。

-Steve
You'll want to use an asynchronous send (e.g., BeginSend).

        -Steve


这篇关于.NET中的异步套接字编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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