Python Tkinter socket.recv not receiving -


i trying make chat program python tkinter, recv function recvmsg() either doesn't receive or doesn't print anything.

could me fix receiving problem? change code anyway want.

from tkinter import * import easygui import socket import threading msgscount = 1  setup = false  def makeserver():     global tcpclisock     host = ''     port = easygui.integerbox(msg='enter port...', title='port', argupperbound=100000)     buffsize = 1024     addr = (host, port)     setup = true      tcpsersock = socket.socket(socket.af_inet, socket.sock_stream)     tcpsersock.bind(addr)     tcpsersock.listen(5)     tcpclisock, addr = tcpsersock.accept()     easygui.msgbox(msg=('connected from: ', addr), title='connected')  def connectserver():     global tcpclisock     setup = true     host = easygui.choicebox(msg='choose host...', title='choose host', choices=('localhost'),buttons=('select')) port = easygui.integerbox(msg='enter port...', title='port', argupperbound=100000) buffsize = 1024 addr = (host, port)  tcpclisock = socket.socket(socket.af_inet, socket.sock_stream) tcpclisock.connect(addr)  def sendmsg():     global msgscount, tcpclisock     try:         msgs.insert(msgscount, ">>" + msg.get())         data = msg.get()         msg.delete(0,end)         msgscount += 1         tcpclisock.send(data)     except:         easygui.msgbox(msg='you need connect server.', title='error')   def recvmsg():     global msgscount,tcpclisock     if setup == true:         datar = tcpclisock.recv(buffsize)         msgs.insert(msgscount, datar)         msgscount += 1         top.after(1000, recvmsg)     else:         answ = easygui.buttonbox(msg='please join or create server', title='server', choices=("create", 'join'))         if answ == "create":             makeserver()         else:             connectserver()   top = tk() top.geometry('640x650')  msgs = listbox(top, width=105, height=43) msgs.pack()  msg = entry(top, bd=2, width=60, font='arial 12 bold') msg.pack(side=left)  sendbtn = button(top, text='send', font='arial 15 bold',width=15, padx=5, pady=5,command=runsendmsg) sendbtn.pack(side=right)  menubar = menu(top) servermenu = menu(menubar, tearoff=0) servermenu.add_command(label="create server", command=makeserver) servermenu.add_command(label="join server", command=connectserver) menubar.add_cascade(label='server', menu=servermenu)  top.config(menu=menubar)  top.after(5000, recvmsg) mainloop() 

i don't have easygui removed code

from tkinter import * #import easygui import socket #import threading  msgscount = 1  setup = false buffsize = 1024  def makeserver():     global tcpclisock,setup,buffsize     host = ''     port = 9000     buffsize = 1024     addr = (host, port)     setup = true      print "makeserver():"      tcpsersock = socket.socket(socket.af_inet, socket.sock_stream)     tcpsersock.bind(addr)     tcpsersock.listen(5)     tcpclisock, addr = tcpsersock.accept()     tcpclisock.setblocking(0)     print 'connected from: ', addr     top.after(1000, recvmsg)  def connectserver():     global tcpclisock,setup,buffsize     setup = true     host = ''     port = 9000     buffsize = 1024     addr = (host, port)      tcpclisock = socket.socket(socket.af_inet, socket.sock_stream)     tcpclisock.connect(addr)     print 'connected to: ', addr     tcpclisock.setblocking(0)     top.after(1000, recvmsg)  def sendmsg():     print 'sendmsg():'     global msgscount, tcpclisock,setup     try:         msgs.insert(msgscount, ">>" + msg.get())         data = msg.get()         msg.delete(0,end)         msgscount += 1         print tcpclisock.send(data)     except:         print 'you need connect server.'   def recvmsg():     global msgscount,tcpclisock,setup,buffsize     print 'recvmsg():', setup     if setup == true:         try:             datar = tcpclisock.recv(buffsize)             msgs.insert(msgscount, datar)             msgscount += 1         except:             pass         top.after(1000, recvmsg)     else:         pass         answ = "create"         if answ == "create":             makeserver()         else:             connectserver()   top = tk() #top.geometry('640x650')  msgs = listbox(top, width=105, height=43) msgs.pack()  msg = entry(top, bd=2, width=60, font='arial 12 bold') msg.pack()  sendbtn = button(top, text='send', font='arial 15 bold', width=15, padx=5, pady=5, command=sendmsg) sendbtn.pack()  menubar = menu(top) servermenu = menu(menubar, tearoff=0) servermenu.add_command(label="create server", command=makeserver) servermenu.add_command(label="join server", command=connectserver) menubar.add_cascade(label='server', menu=servermenu)  top.config(menu=menubar)  mainloop() 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -