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 :: strip first occurence of substring python 
Python :: python - change the bin size of an histogram+ 
Python :: Python Django Models Unique Rows 
Python :: python generate public private key pair 
Python :: python how to remove commas from string 
Python :: python find object with attribute in list 
Python :: print pretty in python 
Python :: numpy vector multiplication 
Python :: how to get today weekday in python 
Python :: sending whatsapp message using python 
Python :: replace column values/create new column based on another column values/condition in Pandas 
Python :: Select rows without NaN in specific column 
Python :: slice dataframe pandas based on condition 
Python :: python hide input 
Python :: opencv python grayscale image to color 
Python :: pandas dataframe get number of occurrence in column 
Python :: del all variables python 
Python :: run python notepad++ 
Python :: feature importance naive bayes python 
Python :: python how to calculate how much time code takes 
Python :: get all subsets of a list python 
Python :: matplotlib figure cut off 
Python :: excel write in row 
Python :: string to list python 
Python :: number of column in dataset pandas 
Python :: pandas check if column is sorted 
Python :: python iterate list 
Python :: numpy array with 2 times each value 
Python :: numpy remove columns containing nan 
Python :: import antigravity in python 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =