对于Python服务器“每个套接字地址通常只允许使用一种”感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍python套接字,并为您提供关于(OS10048)通常每个套接字地址(协议/网络地址/
对于Python服务器“每个套接字地址通常只允许使用一种”感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍python 套接字,并为您提供关于(OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次、apache错误01:通常每个套接字地址(协议/网络地址/端口)只允许使用有一次的解决方法、asp.net – HttpClient:通常只允许使用每个套接字地址(协议/网络地址/端口)、C# 利用 HttpWebRequest 类发送 post 请求,出现 “套接字 (协议 / 网络地址 / 端口) 只允许使用一次” 问题的有用信息。
本文目录一览:- Python服务器“每个套接字地址通常只允许使用一种”(python 套接字)
- (OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次
- apache错误01:通常每个套接字地址(协议/网络地址/端口)只允许使用有一次的解决方法
- asp.net – HttpClient:通常只允许使用每个套接字地址(协议/网络地址/端口)
- C# 利用 HttpWebRequest 类发送 post 请求,出现 “套接字 (协议 / 网络地址 / 端口) 只允许使用一次” 问题
Python服务器“每个套接字地址通常只允许使用一种”(python 套接字)
我正在尝试用python创建一个非常基本的服务器,该服务器侦听端口,在客户端尝试连接时创建TCP连接,接收数据,发回一些东西,然后再次侦听(并无限地重复该过程)。这是我到目前为止所拥有的:
from socket import *serverName = "localhost"serverPort = 4444BUFFER_SIZE = 1024s = socket(AF_INET, SOCK_STREAM)s.bind((serverName, serverPort))s.listen(1)print "Server is ready to receive data..."while 1: newConnection, client = s.accept() msg = newConnection.recv(BUFFER_SIZE) print msg newConnection.send("hello world") newConnection.close()
有时,这似乎工作得很好(如果我将浏览器指向“ localhost:4444”,则服务器将打印出HTTP GET请求,而网页将显示文本“ hello
world”)。但是当我在最后几分钟关闭服务器后尝试启动服务器时,偶尔会收到以下错误消息:
Traceback (most recent call last): File "path\server.py", line 8, in <module> s.bind((serverName, serverPort)) File "C:\Python27\lib\socket.py", line 224, in meth return getattr(self._sock,name)(*args)error: [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted
我正在使用Windows 7在python中进行编程。有关如何解决此问题的任何想法?
答案1
小编典典在调用bind()之前,启用SO_REUSEADDR套接字选项。这允许地址/端口立即重用,而不是将其停留在TIME_WAIT状态几分钟,以等待延迟的数据包到达。
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
(OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次
Apache + Tomcat 在win2k3下,时不时报这样的错误!大家遇到过不?怎么处理的?
(OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次
apache错误01:通常每个套接字地址(协议/网络地址/端口)只允许使用有一次的解决方法
两种解决方法:
1、打开 控制面板->服务 找到 IIS admin 等相应服务 关闭并禁用
2、如果不想关闭IIS服务(因为80端口被IIS占用) 可将apache使用的端口改成其它端口
将apache2/conf/httpd.conf 中的
Listen 80 改为 Listen (你要使用的端口) 如 Listen 8080
不过这时在你访问你的apache 下的Web服务时 在域名后要加上端口号
如: http://localhost:8080
总结
以上是小编为你收集整理的apache错误01:通常每个套接字地址(协议/网络地址/端口)只允许使用有一次的解决方法全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
asp.net – HttpClient:通常只允许使用每个套接字地址(协议/网络地址/端口)
using (var client = new HttpClient()) { client.BaseAddress = new Uri(Url); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml")); using (var task = client.PostAsJsonAsync(Url,body)) { if (task.Result.StatusCode != HttpStatusCode.OK) throw new Exception(task.Result.ReasonPhrase); }
}
不确定为什么我们得到每个套接字地址(协议/网络地址/端口)的唯一用法通常是允许的xx.xxx.xxx.xx:80错误
System.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the Remote Server ---> System.Net.sockets.socketException: Only one usage of each socket address (protocol/network address/port) is normally permitted xx.xx.xx.xx:80 at System.Net.sockets.socket.EndConnect(IAsyncResult asyncResult) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure,Socket s4,Socket s6,Socket& socket,IPAddress& address,ConnectSocketState state,IAsyncResult asyncResult,Exception& exception) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult,TransportContext& context) at System.Net.Http.httpclienthandler.GetRequestStreamCallback(IAsyncResult ar) --- End of inner exception stack trace --- --- End of inner exception stack trace --- at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
解决方法
Address already in use.
Typically,only one usage of each socket
address (protocol/IP address/port) is permitted. This error occurs if
an application attempts to bind a socket to an IP address/port that
has already been used for an existing socket,or a socket that was not
closed properly,or one that is still in the process of closing. For
server applications that need to bind multiple sockets to the same
port number,consider using setsockopt (SO_REUSEADDR). Client
applications usually need not call bind at all—connect chooses an
unused port automatically. When bind is called with a wildcard address
(involving ADDR_ANY),a WSAEADDRINUSE error Could be delayed until the
specific address is committed. This Could happen with a call to
another function later,including connect,listen,WSAConnect,or
WSAJoinLeaf.
这意味着你要么有多个HttpClient对象试图同时将它们绑定到同一个本地IP /端口,要么另一个应用程序正在使用HttpClient试图也使用的IP /端口.
更有可能的是,您可能经常发布HTTP请求,并且可能没有完全消耗响应,这会阻止ASP汇集和重用连接,从而随着时间的推移遇到端口耗尽.
C# 利用 HttpWebRequest 类发送 post 请求,出现 “套接字 (协议 / 网络地址 / 端口) 只允许使用一次” 问题
声明:问题虽然已经被解决,但是并没有明白具体原理,欢迎大佬补充。
最近网站出现一个问题,在 C# 里面使用 HttpWebRequest 类去发送 post 请求,偶尔 会出现 “套接字 (协议 / 网络地址 / 端口) 只允许使用一次” 的异常,很明显应该是端口被占用。
原因排查:
1、网上说最多就是其他程序占用端口:因为已经上线,并且有时候可以正常运行,因此排除其他程序占用端口的可能,而且我网站用的就是 80 端口。
2、第二个可能原因就是接口性能较差,占用较长处理时间:我 给 post 的目标接口(因为接口也是本身网站提供的,因此可以进行监控) 加上时间日志,发现处理时长都在 30ms -50 ms 左右,而且网站访问量并不是很大,因此这个处理速度还是非常快的,按理说不应该出现端口占用情况。
我们现在来看一下 post 代码 ,如下:
private string sendHttpWebRequest(bool isPost, string sendData, string requestURL)
{
UTF8Encoding encoding = new UTF8Encoding();
byte[] data = encoding.GetBytes(sendData);
// 制备web请求
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(requestURL);
if (isPost)
{
myRequest.Method = "POST";
}
else
{
myRequest.Method = "GET";
}
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
if (isPost)
{
Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
}
}
最后 我发现上面的代码并没有接收返回,是因为这个接口本身设计的问题,接口只是为了通知,并不关心返回结果(当然这本身不是一个好的设计) 。
但是经过测试,问题就出在没有接收返回上,加上接收返回的代码以后, “套接字 (协议 / 网络地址 / 端口) 只允许使用一次” 的异常就消失 了!
最后 post 代码如下:
private string sendHttpWebRequest(bool isPost, string sendData, string requestURL)
{
UTF8Encoding encoding = new UTF8Encoding();
byte[] data = encoding.GetBytes(sendData);
// 制备web请求
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(requestURL);
if (isPost)
{
myRequest.Method = "POST";
}
else
{
myRequest.Method = "GET";
}
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
if (isPost)
{
Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
}
//获取响应
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);
return reader.ReadToEnd();
}
到此, “套接字 (协议 / 网络地址 / 端口) 只允许使用一次” 这个问题已经不会再出现了。。。
我们今天的关于Python服务器“每个套接字地址通常只允许使用一种”和python 套接字的分享已经告一段落,感谢您的关注,如果您想了解更多关于(OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次、apache错误01:通常每个套接字地址(协议/网络地址/端口)只允许使用有一次的解决方法、asp.net – HttpClient:通常只允许使用每个套接字地址(协议/网络地址/端口)、C# 利用 HttpWebRequest 类发送 post 请求,出现 “套接字 (协议 / 网络地址 / 端口) 只允许使用一次” 问题的相关信息,请在本站查询。
本文标签: