Skip to content
GitLab
Menu
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
1d32f477
Commit
1d32f477
authored
Apr 25, 2019
by
StevenWdV
Browse files
First working prototype
parent
ac7b2e9b
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
bTCP_client.py
View file @
1d32f477
#!/
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
()
bTCP_server.py
View file @
1d32f477
#!/
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
()
btcp.py
View file @
1d32f477
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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