Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-Erm
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenXG
OpenXG-Erm
Commits
fa365755
Commit
fa365755
authored
Apr 12, 2021
by
Suzhi Bi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
8124e285
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
user4's_code_and_picture/client.py
user4's_code_and_picture/client.py
+46
-0
No files found.
user4's_code_and_picture/client.py
0 → 100644
View file @
fa365755
import
socket
import
sys
import
os
import
struct
def
deal_data
(
conn
,
addr
):
print
(
'Accept new connection from {0}'
.
format
(
addr
))
fileinfo_size
=
struct
.
calcsize
(
'128sq'
)
buf
=
conn
.
recv
(
fileinfo_size
)
if
buf
:
filename
,
filesize
=
struct
.
unpack
(
'128sq'
,
buf
)
fn
=
filename
.
strip
(
str
.
encode
(
'
\00
'
))
fn_1
=
fn
.
decode
().
split
(
'_'
)[
-
1
]
new_filename
=
os
.
path
.
join
(
str
.
encode
(
'./'
),
fn_1
.
encode
())
print
(
'file new name is {0}, filesize if {1}'
.
format
(
new_filename
,
filesize
))
recvd_size
=
0
fp
=
open
(
new_filename
,
'wb'
)
print
(
"start receiving..."
)
while
not
recvd_size
==
filesize
:
if
filesize
-
recvd_size
>
1024
:
data
=
conn
.
recv
(
1024
)
recvd_size
+=
len
(
data
)
else
:
data
=
conn
.
recv
(
filesize
-
recvd_size
)
recvd_size
=
filesize
fp
.
write
(
data
)
fp
.
close
()
print
(
"end receive..."
)
conn
.
close
()
print
(
"Waiting..."
)
ip
=
'192.168.191.8'
try
:
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
s
.
bind
((
ip
,
8085
))
s
.
listen
(
10
)
except
socket
.
error
as
msg
:
print
(
msg
)
sys
.
exit
(
1
)
while
1
:
conn
,
addr
=
s
.
accept
()
deal_data
(
conn
,
addr
)
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