-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add TCPRequestHandler and WebRequestHandler classes
The code changes include adding two new classes, `TCPRequestHandler` and `WebRequestHandler`, to handle TCP and web requests respectively. These classes implement the necessary methods to handle incoming requests and perform the required actions.
- Loading branch information
Showing
3 changed files
with
24 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from socketserver import BaseRequestHandler | ||
|
||
|
||
class TCPRequestHandler(BaseRequestHandler): | ||
|
||
def handle(self): | ||
print(f"Received connection from {self.client_address}") | ||
data = self.request.recv(1024) | ||
print(f"Received data: {data}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from http.server import BaseHTTPRequestHandler | ||
|
||
|
||
class WebRequestHandler(BaseHTTPRequestHandler): | ||
|
||
def do_GET(self): | ||
self.send_response(200) | ||
self.send_header("Content-type", "text/html") | ||
self.end_headers() | ||
self.wfile.write(b"Hello World!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters