Commit ac7b2e9b authored by StevenWdV's avatar StevenWdV

A lot of progress, but still not tested

parent dc5f64be
#!/usr/local/bin/python3
import socket, argparse, random
from struct import *
import argparse
import socket
import struct
import btcp
#Handle arguments
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")
parser.add_argument("-i", "--input", help="File to send", default="tmp.file")
args = parser.parse_args()
destination_ip = "127.0.0.1"
destination_port = 9001
#bTCP header
header_format = "I"
bTCP_header = pack(header_format, randint(0,100))
bTCP_payload = ""
udp_payload = bTCP_header
binding = btcp.Binding(socket.AF_INET, ("", 9002), args.window, args.timeout)
connection = binding.connect_client(0, 0, ("", 9001))
#UDP socket which will transport your bTCP packets
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
file = open(args.input, "rb")
data = file.read()
file.close()
#send payload
sock.sendto(udp_payload, (destination_ip, destination_port))
connection.send(struct.pack("!Q", len(data)))
connection.send(data)
binding.close()
#!/usr/local/bin/python3
import socket, argparse
from struct import *
import argparse
import socket
import struct
#Handle arguments
import btcp
# Handle arguments
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("-o","--output", help="Where to store file", default="tmp.file")
parser.add_argument("-o", "--output", help="Where to store file", default="tmp.file")
args = parser.parse_args()
server_ip = "127.0.0.1"
server_port = 9001
binding = btcp.Binding(socket.AF_INET, ("", 9001), args.window, args.timeout)
server = binding.bind_server(0)
server.start_listen(1)
connection = server.accept()
#Define a header format
header_format = "I"
file_size: int = struct.unpack("!Q", connection.receive(8))[0]
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.bind((server_ip, server_port))
file = open(args.output, "wb")
while file_size > 0:
data = connection.receive_all()
file.write(data)
file_size -= len(data)
file.close()
while True:
data, addr = sock.recvfrom(1016)
print(unpack(header_format,data))
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