Python Server socket.error: [Errno 92] Protocol not available
Question: I wanted to make a server, that recives an command from a client, in the form
of a String and send a String(or a List of Strings) back. The first time, I
run the server and the client, it works perfectly fine, but after the server
send the String to the client, the server crashes with the message:

    
    
    socket.error: [Errno 92] Protocol not available
    

Here is the Server:

    
    
    import socket
    import errno
    
    
    def Main():
        host = '192.168.178.30'
        port = 12345
    
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
        s.bind((host, port))
        s.listen(1)
    
    
        while True:
    
            c, addr = s.accept()
            c.setblocking(0)
    
            print "Connection from: " + str(addr)
    
    
            command = c.recv(1024)
    
            if command == 'GIVETEXT':
                c.send('test')
    
            try:
                c.close()
                s.setsockopt(socket.AF_INET, socket.SOCK_STREAM, 1)
            except socket.error as e:
                if e.errno != errno.ECONNRESET:
                    raise
                pass
    
    if __name__ == '__main__':
        Main()
    

And Here is the client part:

    
    
    import socket
    
    class Client(object):
    
        def __init__(self, *args):
            self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    
        def sent(self, host, port):
            self.s.connect((host, port))
            self.s.send('GIVETEXT')#sends command
    
            self.Text = self.s.recv(1024)
    
            print self.Text
    
            self.s.close
            return self.Text
    


Answer: In the server code, could you comment (or remove) the following line:

    
    
    s.setsockopt(socket.AF_INET, socket.SOCK_STREAM, 1)
    

The setsockopt operation is to define the options of the socket. The level
should be SOL_SOCKET and the differents options can be found in setsockopt man
page: <http://linux.die.net/man/3/setsockopt>

An example would be:

    
    
    s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
    

