Python Forum
send all pictures instead of just two
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
send all pictures instead of just two
#1
The server is supposed to send all pictures from a folder to the client.
By changing the number inside of the parenthesis of s.recv() in the client side
I was able to display two pictures.
My question is, what is stopping my code from sending/displaying them all?
How to fix it?
P.S.
the number inside the parenthesis is the size of one of the pictures.

SERVER
import socket
import glob
import os

host = "127.0.0.1"
port = 5000

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host, port))
s.listen(5)
print("server started...")

path1 = (r"C:\Users\Desktop\opencvpics")

def readFileImages():
    st = os.path.join(path1, "*.jpg")
    print(st)
    return glob.glob(st)

list1 = readFileImages()

print(list1, "list1......")

while True:
    c, addr = s.accept()
    #print(f"connection from {addr} has been established !")
    #c.send(bytes("welcome to the server".encode()))

    for pics in (readFileImages()):
        f = open(pics, 'rb')
        l = f.read()

        #while (l):
        c.sendall(l)
        #print('Sent ', repr(l))
        print(len(l), 'LENGTH L')
        print(f, "how many files")

        f.close()


    print('Done sending')
    c.send('Thank you for connecting'.encode())
CLIENT

import socket
from PIL import Image
import io

host =  "127.0.0.1"
port = 5000

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))

s.send('Hello server!'.encode())

with open('received_file.jpg', 'wb') as f:
    print('file is open')

    while f:

        print('receiving data...')
        #data = s.recv(439813)
        data = s.recv(440179)
        print('data=%s', data, "ASDFASDSADFASDFVSSDSAFSADDFDSAFD")
        f.write(data)
        print('Successfully get the files')
        print('connection closed')
        print(type(data))
        print(len(data))

        image = Image.open(io.BytesIO(data))

        image.show()


s.close()
Reply


Messages In This Thread
send all pictures instead of just two - by mcgrim - Nov-06-2019, 09:35 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020