Fully implement the vote #8
3 changed files with 45 additions and 0 deletions
0
mains/__init__.py
Normal file
0
mains/__init__.py
Normal file
21
mains/client.py
Normal file
21
mains/client.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
|
arg_parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
arg_parser.add_argument("-H", "--host", dest="hostname", type=str, default="127.0.0.1")
|
||||||
|
arg_parser.add_argument("-p", "--port", dest="port", type=int, default=57823)
|
||||||
|
|
||||||
|
arguments = arg_parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
if arguments:
|
||||||
|
import ssl
|
||||||
|
import socket
|
||||||
|
|
||||||
|
context = ssl.create_default_context()
|
||||||
|
|
||||||
|
with socket.create_connection((arguments.hostname, 443)) as sock_client:
|
||||||
|
with context.wrap_socket(sock_client, server_hostname=arguments.hostname) as ssl_sock_client:
|
||||||
|
print(ssl_sock_client.version())
|
||||||
|
ssl_sock_client.send(b"Hello World!")
|
24
mains/server.py
Normal file
24
mains/server.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
|
arg_parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
arg_parser.add_argument("-H", "--host", dest="hostname", type=str, default="0.0.0.0")
|
||||||
|
arg_parser.add_argument("-p", "--port", dest="port", type=int, default=57823)
|
||||||
|
|
||||||
|
arguments = arg_parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
if arguments:
|
||||||
|
import ssl
|
||||||
|
import socket
|
||||||
|
|
||||||
|
context = ssl.create_default_context()
|
||||||
|
|
||||||
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock_server:
|
||||||
|
sock_server.bind((arguments.hostname, arguments.port))
|
||||||
|
sock_server.listen(5)
|
||||||
|
|
||||||
|
with context.wrap_socket(sock_server, server_side=True) as ssl_sock_server:
|
||||||
|
data = ssl_sock_server.recv()
|
||||||
|
print(data)
|
Loading…
Reference in a new issue