File tree 4 files changed +54
-0
lines changed
4 files changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ Hello!
Original file line number Diff line number Diff line change
1
+ Hello from second file
Original file line number Diff line number Diff line change
1
+ import socket
2
+
3
+ HOST = 'localhost'
4
+ PORT = 6666
5
+
6
+ while True :
7
+ request = input ('>' )
8
+
9
+ sock = socket .socket ()
10
+ sock .connect ((HOST , PORT ))
11
+
12
+ sock .send (request .encode ())
13
+
14
+ response = sock .recv (1024 ).decode ()
15
+ print (response )
16
+
17
+ sock .close ()
Original file line number Diff line number Diff line change
1
+ import socket
2
+ import os
3
+ '''
4
+ pwd - показывает название рабочей директории
5
+ ls - показывает содержимое текущей директории
6
+ cat <filename> - отправляет содержимое файла
7
+ '''
8
+
9
+ dirname = os .path .join (os .getcwd (), 'docs' )
10
+
11
+ def process (req ):
12
+ if req == 'pwd' :
13
+ return dirname
14
+ elif req == 'ls' :
15
+ return '; ' .join (os .listdir (dirname ))
16
+ return 'bad request'
17
+
18
+
19
+ PORT = 6666
20
+
21
+ sock = socket .socket ()
22
+ sock .bind (('' , PORT ))
23
+ sock .listen ()
24
+ print ("Прослушиваем порт" , PORT )
25
+
26
+ while True :
27
+ conn , addr = sock .accept ()
28
+
29
+ request = conn .recv (1024 ).decode ()
30
+ print (request )
31
+
32
+ response = process (request )
33
+ conn .send (response .encode ())
34
+
35
+ conn .close ()
You can’t perform that action at this time.
0 commit comments