“袜子,地址= self._sock.accept()套接字。错误:[Errno 95]不支持该操作”

时间:2018-09-26 14:30:47

标签: python ethernet raw-ethernet

我想尝试为服务器端创建一个客户端(通过以太网协议发送原始数据),但是我遇到此错误:

File "/usr/lib/python2.7/socket.py", line 206, in accept
sock, addr = self._sock.accept()

socket.error:[Errno 95]不支持该操作

尽管我这样称呼:sudo python server.py

这是我的server.py代码:

  from socket import *
server= socket(AF_PACKET,SOCK_RAW)

host='eth0'
port=4096

address=(host,port)
server.bind(address)

print("started listening " + host + ": " ,port)
client,addr=server.accept()
print("Got a connection from " + addr[0], ": ",addr[1])
while True:
    data =client.recv(4096)
    print("Received" + data + " from the client" )
    print ("proccesing data")
    if(data == "Hello server"):
        client.send(("Hello client").encode('utf-8'))
        print("  Proccesing done. \n   Reply Send")
    elif(data =="disconnect"):
        client.send(("Goodbye").encode('utf-8'))
        client.close()
        break
    else:
        client.send((" Invalid data ").encode('utf-8'))
        print("  Proccessing done Invalid data . \n Reply send ")

1 个答案:

答案 0 :(得分:0)

根据Sam Maso的评论,这是可行的。我希望这对其他人有帮助。

from socket import *
server= socket(AF_PACKET,SOCK_RAW)

host='eth0'
port=4096

address=(host,port)
server.bind(address)

print("started listening " + host + ": " ,port)


while True:
    data =server.recv(4096)
    print("Received" + data + " from the client" )
    print ("proccesing data")
    if(data == "Hello server"):
        server.send(("Hello client").encode('utf-8'))
        print("  Proccesing done. \n   Reply Send")
    elif(data =="disconnect"):
        server.send(("Goodbye").encode('utf-8'))
        server.close()
        break
    else:
        server.send((" Invalid data ").encode('utf-8'))
        print("  Proccessing done Invalid data . \n Reply send ")