" sock, addr = self._sock.accept() socket.error: [Errno 95] Operation not supported "

6.4k views Asked by At

I want to try create a client for my server side (with send raw data over the ethernet protocole) But i have this error :

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

socket.error: [Errno 95] Operation not supported

Although I am calling this way: sudo python server.py

And this is my server.py codes:

  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

There are 1 answers

0
CKocar On

Accoriding to Sam Maso 's comment and it is workig. I hope this is help for other people.

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 ")