Python'da yeni oldum, C stili programlamada oldukça kullanıyorum ve python'da "if" ifadesiyle ilgili bir hata yaşıyorum. While döngüsünde bir değişkeni artırmaya çalışıyorum; yazdırmadan önce kontrol etmek için bir "if" ifadesi kullanmak, ancak bir sebepten dolayı çalışmıyor. İşte ben benzer hataları gördüm amaIF cümlesi çalışmıyor python
import socket
import time
import threading
tLock = threading.Lock()
shutdown = False
kt = 0
def receving(name, sock):
while not shutdown:
try:
tLock.acquire()
while True:
data, addr = sock.recvfrom(1024)
if kt > 0:
print str(kt)
kt = kt+1
except:
pass
finally:
tLock.release()
host = '127.0.0.1'
port = 0
server = ('127.0.0.1',5000)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((host, port))
s.setblocking(0)
rT = threading.Thread(target=receving, args=("RecvThread",s))
rT.start()
alias = raw_input("Please Enter Your Name: ")
message = raw_input(alias + " Please Enter Your Password:")
while message != 'q':
if message != '':
s.sendto(alias + ":" + message, server)
tLock.acquire()
message = raw_input(alias + "-> ")
tLock.release()
time.sleep(0.2)
shudown = True
rT.join()
s.close()
oradan ne var bir türlü gelmedi Ve burada
host = '127.0.0.1'
port = 5000
clients = []
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((host,port))
s.setblocking(0)
checkpass = False
quitting = False
print "Server Started."
while not quitting:
try:
data, addr = s.recvfrom(1024)
if checkpass == False:
userNa,passWo = data.split(":")
daata =[line.strip() for line in open("passFile.txt",'r')]
for index,item in enumerate(daata):
if userNa == daata[index] and passWo ==daata[index+1]:
checkpass = True
print "Welcome " + userNa +" You have successfully logged in!"
break;
else:
print "Your username and/or password was incorrect try again"
else:
print "well we tried"
if "Quit" in str(data):
quitting = True
if addr not in clients:
clients.append(addr)
print time.ctime(time.time()) + str(addr) + ": :" + str(data)
for client in clients:
s.sendto(data, client)
except:
pass
s.close()
bir sekme alanı verin ve görmek ne bekliyorsunuz ? – kjschiroo
Hangi hata? .... – Signal
Lütfen gördüğünüz hatayı gösteren kısa bir ** tamam ** programı gönderin. Lütfen gördüğünüz çıktıyı ve görmeyi beklediğiniz çıktıyı yayınlayın. Daha fazla bilgi için lütfen [mcve] ve [ask] okuyun. –