Skip to content

Commit 85ba4c0

Browse files
committed
TODO added
1 parent 3a67ec0 commit 85ba4c0

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

OtherSocketExamples/asyncio_stream_simple_server.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
HOST, PORT = "127.0.0.1", 9999
1212

13+
# TODO: mantieni numero di client connessi e ritorna lista con indirizzi
14+
# TODO: trasforma write in writelines e termina con \n
15+
# TODO: usa readline e termina comando con \n
16+
1317

1418
def handle_command(cmd: str, client_stream: asyncio.StreamWriter):
1519
if not cmd: return
@@ -56,20 +60,20 @@ async def server_handler(reader, writer):
5660
writer.close()
5761
break
5862
else:
59-
writer.write(handle_command(cmd, writer).encode())
63+
writer.write(handle_command(cmd, writer).encode()) # TODO: writeline
6064
await writer.drain()
6165

6266

6367
async def main():
6468
global HOST, PORT
65-
try:
66-
HOST = sys.argv[1]
67-
except:
68-
pass
69-
try:
70-
PORT = sys.argv[2]
71-
except:
72-
pass
69+
logging.basicConfig(level=logging.DEBUG, format="%(threadName)s --> %(asctime)s - %(levelname)s: %(message)s",
70+
datefmt="%H:%M:%S")
71+
parser = argparse.ArgumentParser()
72+
parser.add_argument("-a", "--address", help="host address", default=HOST, type=str, dest="address")
73+
parser.add_argument("-p", "--port", help="port number", default=PORT, type=int, dest="port")
74+
args = parser.parse_args() # TODO: non funzionante con asyncio
75+
PORT = args.port
76+
HOST = args.address
7377

7478
logging.info(f"Server running on {HOST}:{PORT}...")
7579

OtherSocketExamples/multithreaded_simple_server.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Connect to this server using netcat or similar utilities
88
"""
9+
# TODO: termina con \n --> adatta ricezione e trasmissione
910

1011
# '0': Return the remote address (client) to which the socket is connected;
1112
# '1': Return the server socket's own address;

OtherSocketExamples/select_simple_server.py

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
HOST, PORT = "127.0.0.1", 9999
1414

15+
# TODO: mantieni numero e lista client connessi
16+
# TODO: sistema socket asincrono con sendall --> fai send e togli quello che ha inviato
17+
# TODO: termina con \n --> adatta ricezione e trasmissione
18+
1519

1620
def handle_command(cmd: str, server_sock: socket, client_sock: socket):
1721
if not cmd: return

OtherSocketExamples/socketserver_simple_server.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
HOST, PORT = "127.0.0.1", 9999
1111

12+
# TODO: termina con \n --> adatta ricezione e trasmissione
1213

1314
class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):
1415

ProtocolImplementation/Protocol.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import os
22
import socket
33

4-
DIMBYTESNUM = 5 # Can be represented up to 2^(5*8) b = 1.0995116 TB
4+
# TODO: sanifica input utente in server --> togli . e / (tutti i caratteri che rendono possibile la navigazione tra cartelle) --> potrebbe rimanare stringa vuota
5+
6+
DIMBYTESNUM = 5 # Can be represented up to 2^(5*8) b = 1 TB
57
BUFFSIZENUM = 1024 # bytes
68
CODEBYTES = 1
79

@@ -74,7 +76,7 @@ def error_file_not_found(self):
7476

7577
class ReliableTransmission:
7678
@classmethod
77-
def recvall(cls, s: socket.socket, size: int):
79+
def recvall(cls, s: socket.socket, size: int): # TODO: usa yeld per ricevere dati fino a size
7880
"""
7981
This method receives size bytes and then returns the received data
8082
@@ -92,7 +94,7 @@ def recvall(cls, s: socket.socket, size: int):
9294
return buf
9395

9496
@classmethod
95-
def recvstring(cls, s: socket.socket, eot: str = "\n", encoding: str = "utf-8"):
97+
def recvstring(cls, s: socket.socket, eot: str = "\n", encoding: str = "utf-8"): # TODO: recvline, EOL
9698
"""
9799
This method receives until eot occurs and then returns the received data
98100

0 commit comments

Comments
 (0)