반응형
image 파일 전송.
client -> server ( 이미지 파일 전송 )
< 1.PNG -> 2.PNG >
1. Server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import socket # Import socket module
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
s.bind((host, port)) # Bind to the port
f = open('2.png','wb')
s.listen(5) # Now wait for client connection.
while True:
c, addr = s.accept() # Establish connection with client.
print ('Got connection from', addr)
print ('Receiving...')
l = c.recv(8096)
while (l):
print ('Receiving...')
f.write(l)
l = c.recv(8096)
f.close()
print ('Done Receiving')
c.send('Thank you for connecting')
c.close() # Close the connec
|
2. Client
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
import socket # Import socket module
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
s.connect((host, port))
f = open('1.png','rb')
print ('Sending...')
l = f.read(8096)
while (l):
print ('Sending...')
s.send(l)
l = f.read(8096)
f.close()
print ('Done Sending')
s.shutdown(socket.SHUT_WR)
print (s.recv(8096))
s.close # Close the socket when done
|
3. 결과 확인.

반응형
'프로그래밍 > PYTHON' 카테고리의 다른 글
[Python]파이썬_Tkinter_동영상재생(OpenCV, Tkinter, 웹캠) (0) | 2020.07.29 |
---|---|
[Python]파이썬_Matplotlib_Tkinter 연결 (0) | 2020.07.23 |
[Python]파이썬_OpencvMat_Tkinter 연결 (0) | 2020.07.22 |
[Python] 파이썬 프로그램 배포시 인증키(시디키,키맵)삽입 (0) | 2020.07.17 |
1. 파이썬 설치 및 환경 구축(PYTHON INSTALL) (0) | 2019.11.14 |