Python Chat Server – 1 – Client/Server Node


Video is ready, Click Here to View ×

# import socket
from socket import *
# form socket import socket, bind, listen, recv, send

HOST = ” #localhost /
# LAN –
PORT = 8000
s = socket(AF_INET, SOCK_STREAM)# 98% of all socket programming will use AF_INET and SOCK_STREAM
s.bind((HOST, PORT))
s.listen(1) # how many connections it can receive at one time
conn, addr = s.accept() # accept the connection
print ‘Connected by’, addr # print the address of the person connected
i = True
while i is True:

28 thoughts on “Python Chat Server – 1 – Client/Server Node

  1. Traceback (most recent call last):
      File "C:/Users/Magnuuuus/AppData/Local/Programs/Python/Python35-32/chat,", line 5, in <module>
        s = socket(AF_INET, SOCK_STREAM)
    NameError: name 'AF_INET' is not defined

  2. So, I made a chat room before i saw this video, and i looked this up to see how i could connect it to a server. I got this code:

    ####Imports Section
    from tkinter import *
    from socket import *

    ####Chat Server
    s = socket(AF_INET, SOCK_STREAM)
    HOST = ''
    PORT = 8000
    s.bind((HOST, PORT))
    conn, addr = s.accept()

    ####Chat Window
    root = Tk()

    textbox = Label(root, text="Type here…")
    entry_1 = Entry(root)


    def sendall():

    button_1 = Button(root, text="Send", command=sendall)
    button_1.grid(row=0, column=3)


    I don't get an error code, but it also doesn't display the tkinter window.

  3. hello,
    i am doing a project in which
    PC(windows 10) is the tcp server
    arduino_uno(with the ethernet shield) is the client
    i am using the twisted networking module in python for echo server
    bt it does'nt work.
    i tried the other way round
    ie PC(windows 10) as tcp client
    arduino_uno(with the ethernet shield) as server
    and it works
    please help
    thank you…………………

  4. I tried this and it opens the certain port you specified right?

    now how do you close that port?

    because when I was testing the program it wouldn't allow me to use the previous port despite already closing the program because the past port was never closed :/

  5. I would start with your personal firewall. I am assuming your running windows. Disconnect from your router and try lower all of your built-in firewall rules and try running it. If it runs, you know for sure it is a personal firewall issue.

  6. Thanks. I`m going to try it right now. As to my question, I found out that the build directory contains files necessary for the exe to run and I was trying just the exe file… my mistake.

  7. I have not tried that program. The only program i've been able to use successfully to create a executable is using GUI2EXE. Which provides a nice graphical user interface and seems to work really well.

  8. I tried to build an exe with cx_freeze but when I run it in Windows 7 it gives me the following error, Fatal Python Error: cannot get zipimporter instance 🙁 I´ve tried two different computers resulting in the same error.

Leave a Reply

Your email address will not be published. Required fields are marked *