# Python socket programming error

**URL:** <https://discuss.python.org/t/python-socket-programming-error/21598>\
**Category:** Python Help\
**Created:** [December 2, 2022, 11:58am UTC](https://discuss.python.org/t/python-socket-programming-error/21598 "2022-12-02T11:58:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hazelsu](https://avatars.discourse-cdn.com/v4/letter/h/71c47a/32.png) [@hazelsu](https://discuss.python.org/u/hazelsu)\
**Post date:** [December 2, 2022, 11:58am UTC](https://discuss.python.org/t/python-socket-programming-error/21598/1 "2022-12-02T11:58:58Z")

</div>

hello.  
I recently started to learn python and I keep having the same problem in the socket programming section.  
I run the same codes in a youtube video that I on my spyder. I followed exact intructions but I cant continue because kernel keep giving me red error.  
here are codes

```auto

#server.py

import socket
import threading

PORT = 5050
SERVER = socket.gethostbyname(socket.gethostname())
ADDR = (SERVER,PORT) 
HEADER = 64
FORMAT = "utf-8" 
DISCONNECT_MESSAGE ="DISCONNECT!"

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(ADDR)

def handle_client(conn,addr):
    print(f"NEW CONNECTİON {addr} connected")
    
    connected = True
    while connected:
        msg.length = conn.recv(HEADER).decode(FORMAT)
        msg.length = int(msg.length)
        msg = conn.recv(msg.length).decode(FORMAT)
        if msg == DISCONNECT_MESSAGE:
            connected = False
            
    print(f"[{addr}] {msg}")  

#conn.close()

def start():
    server.listen()
    print(f"[LISTENING] server is listening on {SERVER}")
    conn, addr = server.accept()
    thread= threading.Thread(target=handle_client, args=(conn, addr))
    thread.start()
    print(f"[ACTİVE CONNECTİONS] {threading.activeCount()-1}")

```

the output

 ![kod](https://us1.discourse-cdn.com/flex002/uploads/python1/original/2X/3/379b3a748b6b45e7fdb53bd337b5b8e650bd6ebb.png)

---

<div class="post-metadata">

**Author:** ![Rosuav](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/rosuav/32/3429_2.png) [@Rosuav](https://discuss.python.org/u/Rosuav)\
**Post date:** [December 2, 2022, 12:24pm UTC](https://discuss.python.org/t/python-socket-programming-error/21598/2 "2022-12-02T12:24:00Z")

</div>

(You don’t need to blur out an IP address that starts `192.168` - it’s a private address that only means anything within your local network. For example, I’m currently on a computer with addresses `192.168.0.19` and `192.168.2.2` - but there can be myriad other computers in the world with either or both of those addresses.)

This doesn’t show any errors. What is the problem here? Possibly there’s additional red text that didn’t make it into the screenshot?

---

<div class="post-metadata">

**Author:** ![dstromberg](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/dstromberg/32/9047_2.png) [@dstromberg](https://discuss.python.org/u/dstromberg)\
**Post date:** [December 4, 2022, 5:49am UTC](https://discuss.python.org/t/python-socket-programming-error/21598/3 "2022-12-04T05:49:24Z")

</div>

It may not be the problem you identified, but there is a (or at least “a”) problem in this code.

Please see:  
[https://stromberg.dnsalias.org/~strombrg/TCP/](https://stromberg.dnsalias.org/~strombrg/TCP/)  
[https://stromberg.dnsalias.org/~strombrg/bufsock.html](https://stromberg.dnsalias.org/~strombrg/bufsock.html)
