无法分配请求的地址 - 可能的原因是什么? [英] Cannot assign requested address - possible causes?

查看:232
本文介绍了无法分配请求的地址 - 可能的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,由一个主服务器和分布式从属服务器。从服务器发送状态更新到服务器,如果服务器没有从一个固定的时期特定的奴隶听到,它标志着从跌。这是一直发生的事情。

I have a program that consists of a master server and distributed slave servers. The slave servers send status updates to the server, and if the server hasn't heard from a specific slave in a fixed period, it marks the slave as down. This is happening consistently.

从检查记录,我发现,从只能够一个状态更新发送到服务器,然后就是始终无法再派更新,总是在电话无法连接()不能分配请求的地址( 99)。

From inspecting logs, I have found that the slave is only able to send one status update to the server, and then is never able to send another update, always failing on the call to connect() "Cannot assign requested address (99).

奇怪的是,从能等几个更新发送到服务器,所有的连接都发生在同一端口上。看来,这个失败的最常见的原因是连接开着,但我无法找到任何东西悬空。是否还有其他可能的解释?

Oddly enough, the slave is able to send several other updates to the server, and all of the connections are happening on the same port. It seems that the most common cause of this failure is that connections are left open, but I'm having trouble finding anything left open. Are there other possible explanations?

要澄清一下,这里是我如何连接:

To clarify, here's how I'm connecting:

struct sockaddr *sa; // parameter
size_t           sa_size; //parameter
int              i = 1;
int              stream;

stream = socket(AF_INET,SOCK_STREAM,0);
setsockopt(stream,SOL_SOCKET,SO_REUSEADDR,&i,sizeof(i));
bindresvport(stream,NULL);
connect(stream,sa,sa_size);

这code是一个函数来获取到另一台服务器的连接,并在其中任何4调用的失败会导致功能失效。

This code is in a function to obtain a connection to another server, and a failure on any of those 4 calls causes the function to fail.

推荐答案

也许SO_REUSEADDR帮助吗?
<一href=\"http://www.unixguide.net/network/socketfaq/4.5.shtml\">http://www.unixguide.net/network/socketfaq/4.5.shtml

Maybe SO_REUSEADDR helps here? http://www.unixguide.net/network/socketfaq/4.5.shtml

这篇关于无法分配请求的地址 - 可能的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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