where sending data to the client but we cant receive the data why?
code for client
from Tkinter import *
import random
import tkSimpleDialog
import socket
import threading
class Client(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.root = Tk()
self.root.geometry('700x350')
self.txtName = Entry(self.root)
self.txtName.pack()
self.txtPass = Entry(self.root)
self.txtPass.pack()
self.btnReg = Button(self.root, command = self.mess)
self.btnReg.pack()
self.start()
self.root.mainloop()
def run(self):
self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serveradd = ('localhost',5038)
self.client.connect(serveradd)
self.client.send(self.name)
xx = self.client.recv(1024)
self.txtName.insert(END,xx)
self.flag = 1
self.receive()
def quitConnection(self):
self.client.send('exit')
self.flag = 0
self.client.close()
self.root.destroy()
def mess(self):
x = self.txtName.get()
self.txtPass.insert(END, x)
self.client.send(x)
## self.txtPass.delete(0,END)
def receive(self):
while self.flag == 1:
x = self.client.recv(1024)
self.txtPass.insert(END,x)
if __name__ == '__main__':
Client()
code for server
import socket
import threading
class ChatServer(threading.Thread):
def __init__(self,dct,counter):
self.dct = dct
self.counter = counter
threading.Thread.__init__(self)
def runs(self):
print '\n Client', self.counter,'connection received'
self.dct[self.counter].send('SERVER: You are now connected to the server')
self.code = 0
self.clientMess=0
while self.code != 1:
if self.clientMess == 'exit':
self.code+=1
else:
self.clientMess = self.dct[self.counter].recv(1024)
for xx in self.dct:
print self.dct.keys()
if xx == self.counter:
pass
else:
self.dct[xx].send(str(self.counter) + ':' + self.clientMess)
counter = 0
host = 'localhost'
port = 5038
data = 1024
serveradd = (host,port)
server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server.bind(serveradd)
server.listen(3)
print 'Server started at port',port,'\n'
while True:
channel, addr = server.accept()
name = channel.recv(data).decode()
print name
print 'LOLOLOLOL'
counter += 1
if counter == 1:
dct = {name:channel}
else:
dct[name] = channel
ChatServer(dct,name).start()