Please perform the code in the ubuntu terminal:
Create and configure a Client / Server architecture that allows the following
operations with files from / to the Client:
Copy, move, delete
Chat between users that allows the exchange of
files, including videos
Well if you mean that coding in ubuntu terminal is opening "Vi" and writing the script in python and then executing that script from ubuntu terminal. Then you are in luck!!!
So, I looked your answer and it is quite interesting, it has some various subparts and I tried to cover all of them, So lets go at each part one by one.
Problem1 : Creating a socket, basically creating two py files one named socket _server and another socket_client.
I will recommend that you should use sublime or any other interface which suits you.
import socket
def server_program():
host = socket.gethostname()
port = 7500
server_socket = socket.socket()
server_socket.bind((host, port))
server_socket.listen(2)
conn, address = server_socket.accept()
print("Connection from: " + str(address))
def Messaging():
while True:
data = conn.recv(1024).decode()
if not data:
break
print("from connected user: " + str(data))
data = input(' -> ')
conn.send(data.encode())
def FileTransfering():
filename='mytext.txt' f = open(filename,'rb') l = f.read(1024) while (l): conn.send(l) print('Sent ',repr(l)) l = f.read(1024) f.close()
conn.close()
if __name__ == '__main__':
server_program()
Now, Socket_client.py
import socket
def client_program():
host = socket.gethostname()
port = 7500
client_socket = socket.socket()
client_socket.connect((host, port))
message = input(" -> ")
def Messaging():
while message.lower().strip() != 'bye':
client_socket.send(message.encode())
data = client_socket.recv(1024).decode()
print('Received from server: ' + data)
message = input(" -> ")
def FileTransfering():
while True: print('receiving data...') data = s.recv(1024) print('data=%s', (data)) if not data: break # write data to a file f.write(data)
client_socket.close()
if __name__ == '__main__':
client_program()
So, look for syntax errors:
Working code is given in the secreenshot
Now, follow the steps to run these codes in the terminal.
Step1:- Open two terminals.
Step2:- In the first terminal locate the py file then type the command python3 socketserver.py and run it. Nothing will happen.
Step3:- In the second terminal locate py file location then type the command python3 socketclient.py and run it. Then type hie.
step4:- Hie will be seen in the first terminal.
Do like the answer.
Now, I hope it helps, if you have any doubt regarding this, just comment it, I will reply as fast as possible.
Get Answers For Free
Most questions answered within 1 hours.