I've made a chat server in Python 3. It establishes a connection with a client, waits for a message from the client, prints the message and saves the message to a txt file. When the client sends the message b'/dc', the client closes the connection and the server should break the loop. Instead, the client closes fine, but the server loop infinitely prints an empty message to the screen.

Server:

```
import socket
import sys
import os
import optparse

def createServer(port):

    # create a TCP socket
    sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    # bind the socket to the port
    server_address = ('localhost', port)
    print("starting up on {} port {}".format(*server_address))
    sck.bind(server_address)

    # put the socket into server mode
    sck.listen(5)

    return sck

def runServer(sck, conn, client, logs):

    # server loop
    while True:
        data = conn.recv(1024)
        if data != b'/dc':
            message = client[0] + ': ' + data.decode() + '\n'
            print(message)
            logs.write(message)
        else:
            conn.close()
            break

def main():

    # option to set port when launching the server
    parser = optparse.OptionParser("Usage: pyhon3 server.py -p <server port>")
    parser.add_option('-p', dest='port', type='int', help="specify target port")
    (options, args) = parser.parse_args()
    port = options.port

    if port == None:
        print(parser.usage)
        exit(0)

    # create server logs
    logs = open('./logs.txt', 'a+')

    # create the socket
    sck = createServer(port)

    # wait for connection and start thread
    conn, client = sck.accept()
    runServer(sck, conn, client, logs)

if __name__ == '__main__':
    main()

```

Client:

```
import socket
import sys

# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Connect the socket to the port where the server is listening
server_address = ('localhost', 10000)
print('connecting to {} port {}'.format(*server_address))
sock.connect(server_address)

while True:

    # Send data
    message = bytes(input('> '), 'utf8')
    if message != b'/dc':
        print('sending {!r}'.format(message))
        sock.sendall(message)
    else:
        break

sock.close()

```

Client output:

```
connecting to localhost port 10000
> test
sending b'test'
> 123
sending b'123'
> /dc

```

Server output:

```
127.0.0.1: test

127.0.0.1: 123

127.0.0.1: 

127.0.0.1: 

127.0.0.1: 

127.0.0.1: 

127.0.0.1: 
...

```