SHARE
TWEET

Messenger

mcneisvesten Jun 20th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import socket
  2.  
  3. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  4. s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  5. s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
  6. s.bind(('0.0.0.0',11719))
  7. while 1:
  8.     message = s.recv(128)
  9.     print (message)
  10.  
  11.  
  12. import socket
  13.  
  14. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  15. sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
  16. while 1:
  17.     sock.sendto('broadcast!',('255.255.255.255',11719))
  18.  
  19.  
  20. from Tkinter import *
  21.  
  22. tk=Tk()
  23. tk.title('MegaChat')
  24. tk.geometry('400x300')
  25. tk.mainloop()
  26.  
  27. from Tkinter import *
  28.  
  29. tk=Tk()
  30. tk.title('MegaChat')
  31. tk.geometry('400x300')
  32. log = Text(tk)
  33. nick = Entry(tk)
  34. msg = Entry(tk)
  35. msg.pack(side='bottom', fill='x', expand='true')
  36. nick.pack(side='bottom', fill='x', expand='true')
  37. log.pack(side='top', fill='both',expand='true')
  38. tk.mainloop()
  39.  
  40. from Tkinter import *
  41.  
  42. tk=Tk()
  43.  
  44. text=StringVar()
  45. name=StringVar()
  46. name.set('HabrUser')
  47. text.set('')
  48. tk.title('MegaChat')
  49. tk.geometry('400x300')
  50.  
  51. log = Text(tk)
  52. nick = Entry(tk, textvariable=name)
  53. msg = Entry(tk, textvariable=text)
  54. msg.pack(side='bottom', fill='x', expand='true')
  55. nick.pack(side='bottom', fill='x', expand='true')
  56. log.pack(side='top', fill='both',expand='true')
  57.  
  58. def loopproc():
  59.     print ('Hello '+ name.get() + '!')
  60.     tk.after(1000,loopproc)
  61.  
  62. tk.after(1000,loopproc)
  63. tk.mainloop()
  64.  
  65. from Tkinter import *
  66.  
  67. tk=Tk()
  68.  
  69. text=StringVar()
  70. name=StringVar()
  71. name.set('HabrUser')
  72. text.set('')
  73. tk.title('MegaChat')
  74. tk.geometry('400x300')
  75.  
  76. log = Text(tk)
  77. nick = Entry(tk, textvariable=name)
  78. msg = Entry(tk, textvariable=text)
  79. msg.pack(side='bottom', fill='x', expand='true')
  80. nick.pack(side='bottom', fill='x', expand='true')
  81. log.pack(side='top', fill='both',expand='true')
  82.  
  83. def loopproc():
  84.     log.insert (END,'Hello '+ name.get() + '!\n')
  85.     tk.after(1000,loopproc)
  86.  
  87. def sendproc(event):
  88.     log.insert (END,name.get()+':'+text.get()+'\n')
  89.     text.set('')
  90.  
  91. msg.bind('<Return>',sendproc)
  92. tk.after(1000,loopproc)
  93. tk.mainloop()
  94.  
  95. import socket
  96. from Tkinter import *
  97.  
  98. tk=Tk()
  99.  
  100. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  101. s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  102. s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
  103. s.bind(('0.0.0.0',11719))
  104.  
  105. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  106. sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1)
  107.  
  108. text=StringVar()
  109. name=StringVar()
  110. name.set('HabrUser')
  111. text.set('')
  112. tk.title('MegaChat')
  113. tk.geometry('400x300')
  114.  
  115. log = Text(tk)
  116. nick = Entry(tk, textvariable=name)
  117. msg = Entry(tk, textvariable=text)
  118. msg.pack(side='bottom', fill='x', expand='true')
  119. nick.pack(side='bottom', fill='x', expand='true')
  120. log.pack(side='top', fill='both',expand='true')
  121.  
  122. def loopproc():
  123.     message = s.recv(128)
  124.     log.insert(END,message)
  125.     tk.after(1,loopproc)
  126.  
  127. def sendproc(event):
  128.     sock.sendto (name.get()+':'+text.get(),('255.255.255.255',11719))
  129.     text.set('')
  130.  
  131. msg.bind('<Return>',sendproc)
  132. tk.after(1,loopproc)
  133. tk.mainloop()
  134.  
  135. import socket
  136. from Tkinter import *
  137.  
  138. tk=Tk()
  139.  
  140. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  141. s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  142. s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
  143. s.bind(('0.0.0.0',11719))
  144.  
  145. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  146. sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1)
  147.  
  148. text=StringVar()
  149. name=StringVar()
  150. name.set('HabrUser')
  151. text.set('')
  152. tk.title('MegaChat')
  153. tk.geometry('400x300')
  154.  
  155. log = Text(tk)
  156. nick = Entry(tk, textvariable=name)
  157. msg = Entry(tk, textvariable=text)
  158. msg.pack(side='bottom', fill='x', expand='true')
  159. nick.pack(side='bottom', fill='x', expand='true')
  160. log.pack(side='top', fill='both',expand='true')
  161.  
  162. def loopproc():
  163.     s.setblocking(False)
  164.     try:
  165.         message = s.recv(128)
  166.         log.insert(END,message+'\n')
  167.     except:
  168.         tk.after(1,loopproc)
  169.         return
  170.     tk.after(1,loopproc)
  171.     return
  172.  
  173. def sendproc(event):
  174.     sock.sendto (name.get()+':'+text.get(),('255.255.255.255',11719))
  175.     text.set('')
  176.  
  177. msg.bind('<Return>',sendproc)
  178. tk.after(1,loopproc)
  179. tk.mainloop()
  180.  
  181. # -*- coding: utf-8 -*-
  182.  
  183. import socket
  184. from Tkinter import *
  185.  
  186. #Решение проблемы Кириллицы
  187. reload(sys)
  188. sys.setdefaultencoding('utf-8')
  189. #-----------------------------
  190.  
  191. tk=Tk()
  192.  
  193. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  194. s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  195. s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
  196. s.bind(('0.0.0.0',11719))
  197.  
  198. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  199. sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1)
  200.  
  201. text=StringVar()
  202. name=StringVar()
  203. name.set('HabrUser')
  204. text.set('')
  205. tk.title('MegaChat')
  206. tk.geometry('400x300')
  207.  
  208. log = Text(tk)
  209. nick = Entry(tk, textvariable=name)
  210. msg = Entry(tk, textvariable=text)
  211. msg.pack(side='bottom', fill='x', expand='true')
  212. nick.pack(side='bottom', fill='x', expand='true')
  213. log.pack(side='top', fill='both',expand='true')
  214.  
  215. def loopproc():
  216.     log.see(END)
  217.     s.setblocking(False)
  218.     try:
  219.         message = s.recv(128)
  220.         log.insert(END,message+'\n')
  221.     except:
  222.         tk.after(1,loopproc)
  223.         return
  224.     tk.after(1,loopproc)
  225.     return
  226.  
  227. def sendproc(event):
  228.     sock.sendto (name.get()+':'+text.get(),('255.255.255.255',11719))
  229.     text.set('')
  230.  
  231. msg.bind('<Return>',sendproc)
  232.  
  233. msg.focus_set()
  234.  
  235. tk.after(1,loopproc)
  236. tk.mainloop()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top