Alright, let me explain my issue to you:
So I made a chat client in Python following some tutorials, but I quickly was limited with it. The problem is that because of this process called blocking, when it came time for the client to receive a message, the whole process would stop until a reply did come through.
So I went along asking some questions here and there, and looking for a way to make the client work so that the client could write as many messages as they wanted without having to wait for a reply first.
So I wrote this:
Trouble is when I run this, it just gets stuck after you type in your input, I added some print commands in the proceeding if functions to see if it could complete any of them, but it doesn't. It seems to get stuck right away.
So I made a chat client in Python following some tutorials, but I quickly was limited with it. The problem is that because of this process called blocking, when it came time for the client to receive a message, the whole process would stop until a reply did come through.
So I went along asking some questions here and there, and looking for a way to make the client work so that the client could write as many messages as they wanted without having to wait for a reply first.
So I wrote this:
Code:
from socket import * import select import sys #because why not? import threading import queue print("New Chat Client Using Select Module") HOST = input("Host: ") PORT = int(input("Port: ")) s = socket(AF_INET,SOCK_STREAM) print("Trying to connect....") s.connect((HOST,PORT)) s.setblocking(0) # Not including setblocking(0) because select handles that. print("You just connected to",HOST,) # Lets now try to handle the client a different way! while True: Incoming_data = [s] Exportable_data = [] Exceptions = [] User_input = input("Your message: ") rlist,wlist,xlist = select.select(Incoming_data,Exportable_data,Exceptions) if User_input == True: Exportable_data += [User_input] print(Exportable_data) if wlist: if Exportable_data is True: print(Exportable_data) i.send(Exportable_data) if rlist: data = i.recv(1024) if data == "": continue
Comment