Commit 1d32f477 authored by StevenWdV's avatar StevenWdV

First working prototype

parent ac7b2e9b
#!/usr/local/bin/python3
#!/bin/python3
import argparse
import logging
import socket
import struct
import sys
import btcp
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
parser = argparse.ArgumentParser()
parser.add_argument("-w", "--window", help="Define bTCP window size", type=int, default=100)
parser.add_argument("-t", "--timeout", help="Define bTCP timeout in milliseconds", type=int, default=100)
parser.add_argument("-i", "--input", help="File to send", default="tmp.file")
args = parser.parse_args()
binding = btcp.Binding(socket.AF_INET, ("", 9002), args.window, args.timeout)
binding = btcp.Binding(socket.AF_INET, None, args.window, args.timeout / 1000.)
connection = binding.connect_client(0, 0, ("", 9001))
file = open(args.input, "rb")
file = open(args.input, "r+b")
data = file.read()
file.close()
connection.send(struct.pack("!Q", len(data)))
connection.send(data)
input("press enter to stop\n")
binding.close()
#!/usr/local/bin/python3
#!/bin/python3
import argparse
import logging
import socket
import struct
import sys
import btcp
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
# Handle arguments
parser = argparse.ArgumentParser()
parser.add_argument("-w", "--window", help="Define bTCP window size", type=int, default=100)
......@@ -12,7 +16,7 @@ parser.add_argument("-t", "--timeout", help="Define bTCP timeout in milliseconds
parser.add_argument("-o", "--output", help="Where to store file", default="tmp.file")
args = parser.parse_args()
binding = btcp.Binding(socket.AF_INET, ("", 9001), args.window, args.timeout)
binding = btcp.Binding(socket.AF_INET, ("", 9001), args.window, args.timeout / 1000.)
server = binding.bind_server(0)
server.start_listen(1)
......@@ -20,11 +24,9 @@ connection = server.accept()
file_size: int = struct.unpack("!Q", connection.receive(8))[0]
file = open(args.output, "wb")
while file_size > 0:
data = connection.receive_all()
file.write(data)
file_size -= len(data)
file = open(args.output, "w+b")
data = connection.receive(file_size)
file.write(data)
file.close()
binding.close()
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment