This repository was archived by the owner on Jan 24, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAdmin-server.py
More file actions
107 lines (88 loc) · 3.25 KB
/
Admin-server.py
File metadata and controls
107 lines (88 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'''MIT License
Copyright (c) 2022 Neelkant Newra
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.'''
import socket
import time
import threading
import tkinter
# Tkinter window
root = tkinter.Tk()
root.title("Admin Chat")
root.geometry("430x500")
root.config(bg="white")
conversation=["\n".center(120)]
# threading recv function
def func():
t = threading.Thread(target=recv)
t.start()
# receive message from User
def recv():
listensocket = socket.socket()
port = 3000
host= 'localhost'
maxconnection = 2
listensocket.bind((host, port))
listensocket.listen(maxconnection)
(clientsocket,address) = listensocket.accept()
while True:
sendermessage =clientsocket.recv(1024).decode()
if not sendermessage == "":
conversation.append("Client: "+sendermessage)
text.set("\n".join(conversation))
label.update()
xr = 0
s = socket.socket()
# sending message to User
def sendmessage():
global xr # send
if xr==0:
hostname = 'localhost'
port = 4000
s.connect((hostname,port))
msg = messagebox.get()
conversation.append("You: "+msg)
text.set("\n".join(conversation))
label.update()
messagebox.delete(0,'end')
s.send(msg.encode())
xr = xr + 1
else:
msg = messagebox.get()
conversation.append("You: "+msg)
text.set("\n".join(conversation))
label.update()
messagebox.delete(0,'end')
s.send(msg.encode())
# threading the sendmessage function
def threadsendmsg():
th = threading.Thread(target = sendmessage)
th.start()
buttons = tkinter.Button(root,text="start",command=func,borderwidth=0)
buttons.place(x=200,y=10)
# Text-field
message = tkinter.StringVar()
messagebox = tkinter.Entry(root,textvariable=message,font=('calibre',10,'normal'),border=2,width=42)
messagebox.place(x=10,y=444)
# Button initially with ReadText command
sendmessagebutton = tkinter.Button(root,text="send",command=threadsendmsg,borderwidth=0)
sendmessagebutton.place(x=350,y=444)
# Display field
text = tkinter.StringVar()
label = tkinter.Label(root, textvariable=text,height=20,width=43,justify=tkinter.LEFT,
anchor='nw',font={"family":"Arial Black", "size":20})
label.place(x=15,y=80)
root.mainloop()