socket.error:[errno 99]无法在python中分配请求的地址和命名空间 [英] socket.error:[errno 99] cannot assign requested address and namespace in python

查看:432
本文介绍了socket.error:[errno 99]无法在python中分配请求的地址和命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器软件说 errno99:使用 127.0.0.1 以外的IP地址时,无法分配请求的地址绑定。

My server software says errno99: cannot assign requested address while using an ip address other than 127.0.0.1 for binding.

但如果IP地址 127.0.0.1 ,则可以正常工作。
它与命名空间有关吗?

But if the IP address is 127.0.0.1 it works. Is it related to namespaces?

我通过调用 execfile()执行我在另一个python程序中的服务器和客户端代码code>。
我实际上正在编辑mininet源代码。我编辑了net.py,在里面我使用了execfile('server.py')execfile('client1.py')和execfile('client2.py')。所以一旦sudo mn --topo single,3被调用以及3个主机的创建,我的服务器和客户端代码将被执行。我已经给出了我的服务器和客户端代码。

I am executing my server and client codes in another python program by calling execfile(). I am actually editing the mininet source code.I edited net.py and inside that I used execfile('server.py') execfile('client1.py') and execfile('client2.py').So as soon as "sudo mn --topo single,3" is called along with the creation of 3 hosts my server and client codes will get executed.I have given my server and client codes below.

#server code
import select 
import socket 
import sys 
backlog = 5 
size = 1024 
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
server.bind(("10.0.0.1",9999)) 
server.listen(backlog) 
input = [server] 
running = 1 
while running: 
    inputready,outputready,exceptready = select.select(input,[],[]) 
    for s in inputready: 
        if s == server: 
            client, address = server.accept() 
            input.append(client)
        else: 
            l = s.recv(1024)
            sys.stdout.write(l)
server.close()


#client code
import socket
import select
import sys
import time
while(1) :
    s,addr=server1.accept()    
    data=int(s.recv(4))
    s = socket.socket()
    s.connect(("10.0.0.1",9999))
    while (1):
        f=open ("hello1.txt", "rb")
        l = f.read(1024)
        s.send(l)
        l = f.read(1024)
        time.sleep(5)
s.close()


推荐答案

将事情简化为基础这是您想要测试的内容:

Stripping things down to basics this is what you would want to test with:

import socket
server = socket.socket() 
server.bind(("10.0.0.1", 6677)) 
server.listen(4) 
client_socket, client_address = server.accept()
print(client_address, "has connected")
while 1==1:
    recvieved_data = client_socket.recv(1024)
    print(recvieved_data)

这可以假设一些事情:


  1. 您的本地IP地址(在服务器上)是10.0.0.1(此视频向您展示

  2. 没有其他软件正在侦听端口6677



另请注意IP地址的基本概念:



尝试以下操作,打开开始菜单,在搜索字段中键入 cmd ,然后按Enter键。
黑色控制台打开后输入 ping www.google.com ,这应该为您提供谷歌的IP地址。这个地址是googles本地IP,它们绑定到那个地址,显然你可以绑定到谷歌拥有的IP地址。

Also note the basic concept of IP addresses:

Try the following, open the start menu, in the "search" field type cmd and press enter. Once the black console opens up type ping www.google.com and this should give you and IP address for google. This address is googles local IP and they bind to that and obviously you can not bind to an IP address owned by google.

请注意,您拥有自己的IP地址集。
首先你拥有服务器的本地IP,但是你拥有你家的本地IP。
在下图中 192.168.1.50 是您可以绑定到的服务器的本地IP。
您仍然拥有 83.55.102.40 但问题是它由路由器拥有,而不是您的服务器。因此,即使您访问 http://whatsmyip.com 并告诉您您的IP 83.55 .102.40 情况并非如此,因为它只能看到你来自哪里..而且你正在从路由器上访问你的互联网。

With that in mind, you own your own set of IP addresses. First you have the local IP of the server, but then you have the local IP of your house. In the below picture 192.168.1.50 is the local IP of the server which you can bind to. You still own 83.55.102.40 but the problem is that it's owned by the Router and not your server. So even if you visit http://whatsmyip.com and that tells you that your IP is 83.55.102.40 that is not the case because it can only see where you're coming from.. and you're accessing your internet from a router.

按顺序为了让您的朋友访问您的服务器(绑定到 192.168.1.50 ),您需要将端口 6677 转发给 192.168.1.50 ,这是在您的路由器中完成的。
假设你落后于其中一个。

In order for your friends to access your server (which is bound to 192.168.1.50) you need to forward port 6677 to 192.168.1.50 and this is done in your router. Assuming you are behind one.

如果你在学校,最有可能出现其他困境和路由器。

If you're in school there's other dilemmas and routers in the way most likely.

这篇关于socket.error:[errno 99]无法在python中分配请求的地址和命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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