Python TCP socket.error with long messages
<p>I'm trying to send a basic message across my LAN network via TCP in Python. 
TCPClient.py:</p>

<pre><code>import socket, sys, time

TCP_IP = "10.0.0.10"
TCP_PORT = 5005
BUFFER_SIZE = 1024
running = True

while running == True:
    try:
        MESSAGE = raw_input("Message: ")
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        print("Connecting...")
        s.connect((TCP_IP,TCP_PORT))
        print("Connected!")
        s.send(MESSAGE)
        data = s.recv(BUFFER_SIZE)
        s.close()

        print("Sent data: %s" % MESSAGE)
        print("Recieved data: %s" % data)
        running = False
        time.sleep(20)
    except socket.error as e:
        print(e)
        time.sleep(1)
    except:
        print(sys.exc_info()[0])
        time.sleep(1)
</code></pre>

<p>And TCPServer.py:</p>

<pre><code>import socket, time, sys

TCP_IP = "10.0.0.10"
TCP_PORT = 5005
BUFFER_SIZE = 20

while True:
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.bind((TCP_IP,TCP_PORT))
        print("Listening for connection...")
        s.listen(1)

        conn,addr = s.accept()
        while 1:
            data = conn.recv(BUFFER_SIZE)
            if not data: break
            print("Recieved data: %s" % data)
            conn.send(data.upper())
            print("Sent data: %s" % data.upper())
        conn.close()
    except TypeError as e:
        print(e)
    except ValueError as e:
        print(e)
    except socket.error as e:
        print(e)
    except:
        print(sys.exc_info()[0])
        time.sleep(1)
</code></pre>

<p>It mostly works for small messages (like "hello world") but when I send a message more than ~10 characters it splits it into 2 sections and sometimes doesn't even send half of it. E.g:</p>

<p><a href="https://i.stack.imgur.com/3Ccer.png" rel="nofollow"><img src="https://i.stack.imgur.com/3Ccer.png" alt="running both scripts"></a></p>

<p>Thanks for any help in advanced! much appreciated.</p>

<p>Here's what happened: </p>

<ol>
<li>your client sent long line</li>
<li>your server got 20 characters of that long line (that's size of your buffer on server side)</li>
<li>your server sent back data (20 characters of line) to client</li>
<li>your client got data and disconnected from server, causing server to raise exception.</li>
</ol>

python sockets tcp