bTCP_client.py 807 Bytes
Newer Older
StevenWdV's avatar
StevenWdV committed
1
#!/bin/python3
2
import argparse
StevenWdV's avatar
StevenWdV committed
3
import logging
4
5
import socket
import struct
StevenWdV's avatar
StevenWdV committed
6
import sys
7
8

import btcp
StevenWdV's avatar
StevenWdV committed
9

StevenWdV's avatar
StevenWdV committed
10
11
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)

StevenWdV's avatar
StevenWdV committed
12
13
14
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)
15
parser.add_argument("-i", "--input", help="File to send", default="tmp.file")
StevenWdV's avatar
StevenWdV committed
16
17
args = parser.parse_args()

18
binding = btcp.Binding(socket.AF_INET, None, args.window, args.timeout)
19
connection = binding.connect_client(0, 0, ("", 9001))
StevenWdV's avatar
StevenWdV committed
20

StevenWdV's avatar
StevenWdV committed
21
file = open(args.input, "r+b")
22
23
data = file.read()
file.close()
StevenWdV's avatar
StevenWdV committed
24

25
26
connection.send(struct.pack("!Q", len(data)))
connection.send(data)
StevenWdV's avatar
StevenWdV committed
27
28

input("press enter to stop\n")
29
binding.close()