Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Steven Wallis de Vries
bTCP
Commits
ac7b2e9b
Commit
ac7b2e9b
authored
Apr 19, 2019
by
StevenWdV
Browse files
A lot of progress, but still not tested
parent
dc5f64be
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
bTCP_client.py
View file @
ac7b2e9b
#!/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
()
bTCP_server.py
View file @
ac7b2e9b
#!/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
()
btcp.py
View file @
ac7b2e9b
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment