Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python send image server

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import socket
import os

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("", 12345)) #if the clients/server are on different network you shall bind to ('', port)

s.listen(10)
c, addr = s.accept()
print('{} connected.'.format(addr))

f = open("image.jpg", "rb")
l = os.path.getsize("image.jpg")
m = f.read(l)
c.send_all(m)
f.close()
print("Done sending...")
Comment

python send image client

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("server_public_ip", 12345)) # here you must past the public external ipaddress of the server machine, not that local address

f = open("recieved.jpg", "wb")
data = None
while True:
    m = s.recv(1024)
    data = m
    if m:
        while m:
            m = s.recv(1024)
            data += m
        else:
            break
f.write(data)
f.close()
print("Done receiving")
Comment

PREVIOUS NEXT
Code Example
Python :: extra import on django 
Python :: python "urllib3" download and save pdf 
Python :: random list 
Python :: how to skip number in while loop python 
Python :: inline if statement python return 
Python :: tuple methods in python 
Python :: wails install 
Python :: numpy random entries not repeat 
Python :: how to check if some file exists in python 
Python :: How to change application icon of pygame 
Python :: activate venv environment 
Python :: python random number between 0 and 1 
Python :: Openpyxl automatic width 
Python :: NumPy bitwise_xor Syntax 
Python :: python toupper 
Python :: fastest way to compute pair wise distances python 
Python :: beautifulsoup remove tag with class 
Python :: interface in python 
Python :: pyton count senteses in a text file 
Python :: how to input a full array in one input in python 
Python :: how to make a new key in a dictionary python 
Python :: how to get var value by name godot 
Python :: plotly create plot 
Python :: us states and capitals dictionary 
Python :: python - extract min and max values per each column name 
Python :: python tkinter cheat sheet 
Python :: how to put my graph in tkinter interface 
Python :: How to remove case sensitive django filter 
Python :: remove list from list python 
Python :: convert utm to decimal degrees python 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =