how to connect multiple authenticated clients’ with Django channels Websocket and clients should be connected before opening the channels

so I’m working on the desktop based app that requires a socket handle multiple authenticated clients with Django channel and clients should be authenticated by server before opening the channels and server running on one different system and clients connecting multiple system. I have tried to connect socket with different platform with much effort, I have failed to connect it. is it possible to connect clients in different platform to the server? if yes please help me to resolve this issue because I am new in this technology.

my question is using the code below how would be able to have multiple clients connected? I have tried lists, but I just cant figure out the format for that. How can accomplished where multiple clients connected at Websocket and l am able to send a data to a specific or multiple clients? and how can I add channels in below code?

server.py

import socket

serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

serversocket.bind(('localhost', 8080))

serversocket.listen(10)  # become a server socket connections

while True:
    connection, address = serversocket.accept()
    buf = connection.recv(64)
    if len(buf) > 0:
        print(buf)
        break

here client script I don't want to send data using api any other way to get data from server side 

client.py
def register_user():
    username = reg_username_entry.get()
    password = reg_password_entry.get()
    if not username or not password:
        messagebox.showerror("Input Error", "Please enter a username and password.")
        return

    data = {
        'username': username,
        'password': password
    }

    try:
        response = requests.post("http://127.0.0.1:8000/api/register/", json=data)
        if response.status_code == 200:
            messagebox.showinfo("Success", response.json()['success'])
        else:
            try:
                error_message = response.json().get('error', 'Registration failed')
            except ValueError:
                error_message = response.text
            messagebox.showerror("Error", error_message)
    except requests.exceptions.RequestException as e:
        messagebox.showerror("Request failed", str(e))


def login_user():
    hostname = socket.gethostname()
    ip_address = socket.gethostbyname(hostname)

    username = login_username_entry.get()
    password = login_password_entry.get()
    if not username or not password:
        messagebox.showerror("Input Error", "Please enter a username and password.")
        return

    data = {
        'username': username,
        'password': password
    }

    try:
        response = requests.post("http://127.0.0.1:8000/api/login/", json=data)
        if response.status_code == 200:
            messagebox.showinfo("Success", response.json()['success'])
            # messagebox.showinfo("Message", "Hey There! I hope you are doing well.")
            clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            clientsocket.connect(('localhost', 8080))
            clientsocket.send(bytes('Socket Connected!', 'utf-8'))
            print(f"Hostname: {hostname}")
            print(f"IP Address: {ip_address}")

        else:
            try:
                error_message = response.json().get('error', 'Login failed')
            except ValueError:
                error_message = response.text
            messagebox.showerror("Error", error_message)
    except requests.exceptions.RequestException as e:
        messagebox.showerror("Request failed", str(e))

I need your valuable suggestions or feedback would be highly appreciated.


thank your !

New contributor

Kaumudi Kalikar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật