Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import threading
import tkinter as tk
from tkinter import simpledialog, scrolledtext, ttk
from plyer import notification

# Client setup
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('localhost', 12345))
client.connect(('localhost', 1234))

def receive_messages():
while True:
Expand All @@ -17,14 +18,27 @@ def receive_messages():
typing_status_label.config(text=message)
else:
chat_box.config(state=tk.NORMAL)
# Notification for join/leave messages
if "joined the chat" in message or "left the chat" in message:
notification.notify(
title='Chat Notification',
message=message,
timeout=5
)
if message.startswith(username):
chat_box.insert(tk.END, message + '\n', 'self')
else:
chat_box.insert(tk.END, message + '\n', 'other')
# Show notification only if it's not the user's own message
notification.notify(
title='Chat Application',
message=message,
timeout=2
)
chat_box.config(state=tk.DISABLED)
chat_box.yview(tk.END)
except:
print('An error occurred!')
except Exception as e:
print(f'An error occurred! {e}')
client.close()
break

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
plyer==2.1.0
4 changes: 2 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Server setup
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('localhost', 12345))
server.bind(('localhost', 1234))
server.listen()

clients = []
Expand Down Expand Up @@ -55,4 +55,4 @@ def receive_connections():
thread.start()

print('Server is listening...')
receive_connections()
receive_connections()