Araeynn commited on
Commit
1bdbce8
1 Parent(s): d6ed2a1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import socketserver
2
+
3
+ class TCPHandler(socketserver.StreamRequestHandler):
4
+ """
5
+ The request handler class for our server.
6
+
7
+ It is instantiated once per connection to the server, and must
8
+ override the handle() method to implement communication to the
9
+ client.
10
+ """
11
+
12
+ def handle(self):
13
+ # self.rfile is a file-like object created by the handler;
14
+ # we can now use e.g. readline() instead of raw recv() calls
15
+ self.bytes = self.rfile.read()
16
+ self.data = self.bytes.decode("utf-8")
17
+ with open("script.py", "w") as f:
18
+ f.write(self.data)
19
+ # Likewise, self.wfile is a file-like object used to write back
20
+ # to the client
21
+ self.wfile.write(self.bytes.upper())
22
+
23
+
24
+ if __name__ == "__main__":
25
+ HOST, PORT = "localhost", 9999
26
+
27
+ # Create the server, binding to localhost on port 9999
28
+ with socketserver.TCPServer((HOST, PORT), TCPHandler) as server:
29
+ # Activate the server; this will keep running until you
30
+ # interrupt the program with Ctrl-C
31
+ server.serve_forever()