Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Sending Image through Socket Programming

I am taking screenshot using ImageGrab from PIL library and want to send same from server to client.
I am able to send messages bidirectionally. but can't figure out sending objects or anything other than messages

Server Code :
Code
import socket
import cv2
from PIL import ImageGrab
mysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysocket.bind(("xx.xx.xx.xx",6666))
mysocket.listen(5)
(client, (ip, port)) = mysocket.accept()
image = ImageGrab.grab()
msg = "test"
client.send(msg.encode())
#
#
#

Client Code:
Code
import socket
import cv2

mysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysocket.connect(("xx.xx.xx.xx",6666))
data = mysocket.recv(1024)
print(data)

If you can, please replace code with image i am trying to send
Thanks  🎉
Try something like this (sorry, i dont have time to replace into your code):
Code
From PIL import ImageGrab
import numpy as np

printscreen = ImageGrab.grab(bbox=(0, 0, 800, 600)
printscreen_np = np.array(printscreen.getData(), dtype='uint8')
This would take the pixels and puts them in an array
( see python GTA AI tutorial: https://www.youtube.com/watch?v=ks4MPfMq8aQ )
The best method i think is to convert the img to a string.
After this u can use base64 to compress the string and send it.
Read this post on Stackoverflow.com
https://stackoverflow.com/questions/4245...-in-python
Hi , I need some help in socket programming as well, could anyone here tell me how can I make something like a client querying data from the server (maybe a dictionary storing stock and their prices) send data from server to the client (according to the request like stock first and then prices maybe price of multiple stocks at a time). Can I also make the data look in a tabular form as well on the client end?

I'm at the point where I have done simple client-server code did played with a dictionary and tried sending it over to the client but comes as a single vertical line not in a tabular form, is this even possible? I'm fairly new to python so..
please Guide me through some references if possible.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by LilDeepWebJan 29, 2022 10:06 AM 3 224 Jan 29, 2022 10:06 AM
Last Post: yuumi
[C#] by C++Dec 29, 2019 06:16 PM 16 827 Dec 29, 2019 06:16 PM
Last Post: DNA
[C] by mafiaboySep 6, 2019 11:37 AM 13 434 Sep 6, 2019 11:37 AM
Last Post: zp_city