Python:Errno 10053 when both the server and the client are in the same system
Question: I'm just beginning to code using Python and Python Networking is a whole new
topic for me!I couldn't find out what the problem was and I say, I have tried
all the solutions provided by the user!

Please help me with this code!

Server Code:

    
    
    from socket import *
    import time
    
    HostName = ''
    PortNum = 2015
    Buff = 5000
    ServAdd = (HostName, PortNum)
    ServSoc = socket(AF_INET, SOCK_STREAM)
    ServSoc.bind(ServAdd)
    ServSoc.listen(5)
    
    while 1:
        CliAdd = ServSoc.accept()
        TempSoc = ServSoc.accept()
        while 1:
            CliData = TempSoc.recv(Buff)
            print CliData
            time.sleep(20)
            TempSoc.send('Hai')
        TempSoc.close()
    ServSoc.close()
    

Client Code:

    
    
    from socket import *
    import time
    
    HostName = 'localhost'
    PortNum = 2015
    Buff = 5000
    ServAdd = (HostName, PortNum)
    
    CliSoc = socket(AF_INET, SOCK_STREAM)
    CliSoc.connect(ServAdd)
    
    while 1:
        Data = raw_input('Enter Data to sent to the Server: ')
        CliSoc.send(Data)
        ServData = CliSoc.recv(Buff)
        print ServData
        time.sleep(10)
    CliSoc.close()
    

The Error message is

    
    
    Enter Data to sent to the Server: hello
    
    Traceback (most recent call last):
      File "C:/Python26/Progs/TCPClient.py", line 15, in <module>
        ServData = CliSoc.recv(Buff)
    error: [Errno 10053] An established connection was aborted by the software in your host machine
    


Answer: Try following server code. Your client side seems ok. You have to run
server.py first to listen related port. Then run your client.py. What you do
at the server side is creating a socket to listen (which is "ServSoc" in your
case) and accept connections. Connections are not socket objects so using
`close()` function is not meaningful. Following server code accepts
connections in a loop and check client connection. Thus, it wont crush when
client disconnects.

**Server code:**

    
    
    from socket import *
    import time
    
    HostName = ''
    PortNum = 2015
    Buff = 5000
    ServAdd = (HostName, PortNum)
    ServSoc = socket(AF_INET, SOCK_STREAM)
    ServSoc.bind(ServAdd)
    ServSoc.listen(5)
    
    while 1:
        conn, addr = ServSoc.accept()
        if conn:
            print "connection established with client:",addr
            CliData = conn.recv(Buff)
            print CliData
            time.sleep(1)
            conn.send('Hai')
    ServSoc.close()
    

