Skip to content
Snippets Groups Projects
Commit db43c384 authored by Ethan Robert's avatar Ethan Robert
Browse files

Finished Student side

parents
Branches
No related tags found
No related merge requests found
import socket
FILE = 'message.txt'
class Socket:
def __init__(self):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.bind(('0.0.0.0', 25566))
self.message = ""
def readMessage(self):
with open(FILE, 'r') as file:
self.message = file.read()
def start(self):
self.socket.listen(1)
while True:
client_socket, client_address = self.socket.accept()
# Grab the new message from the file
readMessage()
if self.message == '':
client_socket.close()
else:
# Send the message to the client (teacher)
client_socket.send(self.message.encode('UTF-8'))
# Wait for the pong
response = client_socket.recv(1024).decode('UTF-8')
if response == "Ok":
self.message = ""
client_socket.close()
\ No newline at end of file
FILE = 'message.txt'
def writeMessage(message):
with open(FILE, 'w') as file:
file.write(message)
file.close()
def clearMessage():
with open(FILE, 'w') as file:
file.write("")
file.close()
while True:
message = input("> ")
writeMessage(message)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment