Windows 8的 - .NET TCP AcceptAsync方法回调不费一枪(阻止到Console.ReadLine()) [英] Windows 8 - .NET TCP AcceptAsync callback not firing (blocked by Console.ReadLine())

查看:250
本文介绍了Windows 8的 - .NET TCP AcceptAsync方法回调不费一枪(阻止到Console.ReadLine())的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到具体到Windows 8和VS2012的问题。

I'm experiencing an issue specific to Windows 8 and VS2012.

我有一个TCP套接字服务器和客户端,并在做本地网络上的一些测试。随着Sysinternals的套装软件,我可以看到数据包从TCP客户端发送,并在TCP服务器(我看包柜增加)到达。

I have a TCP socket server and client and am doing some testing on the local network. With sysinternals TCPView, I can see that packets are sent from the TCP client and arrive at the TCP Server (I see the packet counters increase).

然而,它显示为如果数据不能够进入应用栈?
非常相同构建运行不会对Windows 7的问题。

However, it appears as if the data is not making it to the application stack? The very same build runs without issues on Windows 7.

我有Windows 8的防火墙关闭和打开域管理员的用户运行具有提升的权限都处理与UAC关闭。

I have the Windows 8 firewall turned off and run both process with elevated permissions on a domain admin users with UAC turned off.

在我的客户端连接到外部服务器(一个单独的机器上运行),一切工作正常。
还有什么在Windows 8可能会禁止本地进程之间的TCP数据通信?

When I connect the client to a an outside server (running on a separate machine), everything works fine. Is there anything else in Windows 8 that could prohibit TCP data communication between local processes?

谢谢,

修改

要在我的服务器应用程序,确保没有造成这个问题,我建立了一个快速的TCP服务器在控制台应用程序,与插座的构造函数下面的代码:

To make sure nothing in my server application is causing this issue, I built a quick TCP server in a console application, with the following code for the socket constructor:

listenerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

和监听同一个IP /端口作为我的服务器应用程序。
我遇到了同样的问题,我可以telnet到端口,但listenerSocket.AcceptAsync从来没有击中。

and listen on the same local IP/Port as my server application. I'm experiencing the same issue, I can telnet to the port but listenerSocket.AcceptAsync is never hit.

编辑2

在进一步的测试,它appers如果我使用像socket.Accept同步调用()我的问题牵扯到与使用异步套接字调用,也就是说,测试应用程序工作是否正常。然而,当我使用异步套接字调用,即socket.AcceptAsync(),我遇到中提到的问题。到目前为止,我无法找到的WIN7与放大器之间的差异没有提到; 8关于异步套接字调用。

Upon further testing, it appers my issue has something to do with the use of the Async socket calls, i.e. if I use the synchronous calls like socket.Accept(), the test application is performing normally. However, when I use Async socket calls, i.e. socket.AcceptAsync(), I'm experiencing the issues mentioned. So far I couldn't find any mention of differences between win7 & 8 in regards to async socket calls.

下面是我快速的示例应用程序,其中显示了异步回调永远不会触发。这段代码工作正常在Windows 7,但在Windows 8中不起作用(尝试远程连接到127.0.0.1:7000)。

Here's my quick sample app that shows that the async callback is never triggered. This snippet works fine in Windows 7 but does not work in Windows 8 (try to telnet to 127.0.0.1 : 7000).

    class Program
{
    private static SocketAsyncEventArgs socketAsyncEventArgs = new SocketAsyncEventArgs();

    static void Main(string[] args)
    {
        var listenerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        listenerSocket.Bind(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7000));
        listenerSocket.Listen(100);

        socketAsyncEventArgs.Completed += AcceptEventArg_Completed;
        listenerSocket.AcceptAsync(socketAsyncEventArgs);

        Console.ReadLine();
    }

    private static void AcceptEventArg_Completed(object sender, SocketAsyncEventArgs e)
    {
        Console.WriteLine("AcceptEventArg_Completed");
    }
}

修改3

我找到的另汇报Microsoft Connect上的同一个问题:
https://connect.microsoft.com/VisualStudio/feedback/details/759913/socketasynceventargs-completed-doesnt-fire-in-net -framework-4-5

http://connect.microsoft.com/VisualStudio/feedback/details/747218/saea-not-working-in-net-4-5-rp

I found 2 others reporting the same issue on Microsoft Connect: https://connect.microsoft.com/VisualStudio/feedback/details/759913/socketasynceventargs-completed-doesnt-fire-in-net-framework-4-5 and http://connect.microsoft.com/VisualStudio/feedback/details/747218/saea-not-working-in-net-4-5-rp

然而,因为它似乎断定有一个在到Console.ReadLine()调用Windows的错误,它是导致该问题并阻止异步回调:第二个很有趣。

Whereas the 2nd one is interesting as it seems to conclude there is a Windows bug in the Console.ReadLine() call and it is causing the issue and blocking the async callback. If I replace Console.ReadLine() in my snippet with:

            while (true)
        {
            System.Threading.Thread.Sleep(10);
        }



一切工作正常。

everything works fine.

推荐答案

请参阅本:的 GetQueuedCompletionStatus时不能出列IOCP IO如果最初发出的IO是Windows 8的

这是一个错误在Windows 8和2012年,影响其使用的AcceptEx和ReadFile的所有程序。至于现在,只有这两个功能已知受影响。

It's a bug in windows 8 and 2012 and affect all programs which used AcceptEx and ReadFile. As for now, only these two functions are known affected.

这篇关于Windows 8的 - .NET TCP AcceptAsync方法回调不费一枪(阻止到Console.ReadLine())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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