我想尝试为我的服务器端创建一个客户端(通过以太网协议发送原始数据)但我有这个错误:
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 ")