一尘不染

socket.error:[errno 99]无法在python中分配请求的地址和名称空间

python

我的服务器软件说errno99: cannot assign requested address,使用的不是127.0.0.1绑定IP地址。

但是,如果IP地址是127.0.0.1可行的。它与名称空间有关吗?

我正在通过调用python在另一个python程序中执行服务器和客户端代码execfile()。我实际上是在编辑mininet源代码。我编辑了net.py,并在其中使用了execfile(’server.py’)execfile(’client1.py’)和execfile(’client2.py’)。因此,
sudo mn –topo single,3“随着创建3个主机而被调用,我的服务器和客户端代码将被执行。我在下面给出了我的服务器和客户端代码。

#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()

阅读 141

收藏
2020-12-20

共1个答案

一尘不染

简而言之,这就是您要测试的内容:

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. Your local IP address (on the server) is 10.0.0.1 (This video shows you how)
  2. No other software is listening on port 6677

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.

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.

enter image description here

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.

2020-12-20