Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #40951
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-03-09 07:26 -0800 |
| Message-ID | <f9f28b67-cf81-4d9e-96fd-fe4e75fb8c9c@googlegroups.com> (permalink) |
| Subject | http://stackoverflow.com/questions/15311450/my-chat-client-freezes-up-after-beginning-threads |
| From | Owatch <charles.xrandolph2@gmail.com> |
I made a better chat client following help from people:
They told me that if I didn't want to be blocked on .recv when waiting for messages, I would need to use threads, classes, functions, and queues to do so.
So I followed some help a specific person gave me where I created a thread from a class and then defined a function that was supposed to read incoming messages and print them.
I also created a function that allows you to enter stuff to be sent off.
Thing is, when I run the program. Nothing happens.
Can somebody help point out what is wrong? (I've asked questions and researched for 3 days, without getting anywhere, so I did try)
from socket import *
import threading
import json
import select
print("Client Version 3")
HOST = input("Connect to: ")
PORT = int(input("On port: "))
# Create Socket
s = socket(AF_INET,SOCK_STREAM)
s.connect((HOST,PORT))
print("Connected to: ",HOST,)
#-------------------Need 2 threads for handling incoming and outgoing messages--
# 1: Create out_buffer:
Buffer = []
rlist,wlist,xlist = select.select([s],Buffer,[])
class Incoming(threading.Thread):
# made a function a thread
def Incoming_messages():
while True:
for i in rlist:
data = i.recv(1024)
if data:
print(data.decode())
# Now for outgoing data.
def Outgoing():
while True:
user_input=("Your message: ")
if user_input is True:
Buffer += [user_input.encode()]
for i in wlist:
s.sendall(Buffer)
Buffer = []
Thanks for taking a look, thanks also to Tony The Lion for suggesting this
If the code isnt done right, here's a link to view it, and download:
View: http://i1267.photobucket.com/albums/jj554/owatch/PPP_zps4beb891b.png
Download: http://www.mediafire.com/?u51a9b5axfffoxl
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
http://stackoverflow.com/questions/15311450/my-chat-client-freezes-up-after-beginning-threads Owatch <charles.xrandolph2@gmail.com> - 2013-03-09 07:26 -0800
Re: http://stackoverflow.com/questions/15311450/my-chat-client-freezes-up-after-beginning-threads Andrew Berg <bahamutzero8825@gmail.com> - 2013-03-09 10:35 -0600
Re: http://stackoverflow.com/questions/15311450/my-chat-client-freezes-up-after-beginning-threads Owatch <charles.xrandolph2@gmail.com> - 2013-03-09 13:23 -0800
csiph-web