“指定的网络名称不再可用"在Httplistener中 [英] "Specified network name is no longer available" in Httplistener

查看:626
本文介绍了“指定的网络名称不再可用"在Httplistener中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个简单的Web服务,该服务仅使用HttpListener来接收和发送请求.有时,服务失败,并显示指定的网络名称不再可用".当我写入HttpListenerResponse的输出缓冲区时,它似乎被抛出.

I have built a simple web service that simply uses HttpListener to receive and send requests. Occasionally, the service fails with "Specified network name is no longer available". It appears to be thrown when I write to the output buffer of the HttpListenerResponse.

这是错误:

ListenerCallback()错误:System.Net.HttpResponseStream.Write(Byte []缓冲区,Int32偏移量,Int32大小)不再提供指定的网络名称

ListenerCallback() Error: The specified network name is no longer available at System.Net.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 size)

,这是代码的有罪部分. responseString是正在发送回客户端的数据:

and here is the guilty portion of the code. responseString is the data being sent back to the client:

            buffer = System.Text.Encoding.UTF8.GetBytes(responseString);

            response.ContentLength64 = buffer.Length;
            output = response.OutputStream;
            output.Write(buffer, 0, buffer.Length);

它似乎并不总是一个巨大的缓冲区,两个示例分别是3,816字节和142,619字节,这些错误相隔约30秒抛出.我不认为我的单个客户端应用程序会超载HTTPlistener.该客户端偶尔会突发发送/接收数据,并且一次又一次地进行几次交换.

It doesn't seem to always be a huge buffer, two examples are 3,816 bytes and, 142,619 bytes, these errors were thrown about 30 seconds apart. I would not think that my single client application would be overloading HTTPlistener; the client does occasionally sent/receive data in bursts, with several exchanges happening one after another.

大多数Google搜索表明这是一个常见的IT问题,当出现网络问题时,会显示此错误-大多数帮助是针对系统管理员诊断应用程序的问题,而不是针对开发人员查找错误.我的应用程序已经在不同的机器,网络等上进行了测试,我认为这不仅仅是网络配置问题.

Mostly Google searches shows that this is a common IT problem where, when there are network problems, this error is shown -- most of the help is directed toward sysadmins diagnosing a problem with an app moreso than developers tracking down a bug. My app has been tested on different machines, networks, etc. and I don't think it's simply a network configuration problem.

此问题可能是什么原因?

What may be the cause of this problem?

推荐答案

当指定了ContentLength64KeepAlivefalse时,我也得到了它.似乎客户端正在检查Content-Length标头(通过所有可能的帐户,该标头均已正确设置,因为我得到了任何其他值的异常),然后说帮助我完成KTHXBYE"并关闭连接在基础HttpListenerResponse流所期望的之前一点.现在,我只是捕获异常并继续前进.

I'm getting this too, when a ContentLength64 is specified and KeepAlive is false. It seems as though the client is inspecting the Content-Length header (which, by all possible accounts, is set correctly, since I get an exception with any other value) and then saying "Whelp I'm done KTHXBYE" and closing the connection a little bit before the underlying HttpListenerResponse stream was expecting it to. For now, I'm just catching the exception and moving on.

这篇关于“指定的网络名称不再可用"在Httplistener中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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