Python Socket, No Data Recieved after Initial Transmission
I'm looking to make a very basic remote desktop application. Right now I
am able to capture the screen data using the python win32 API, and I am
able to send one image over the socket connection, and rebuild it
correctly on the receiving end. The problem I am having is when I try to
send a second image. Basically it seems like the second set of data is not
arriving on the other end. Here is my code:
Client Side:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('localhost', 8888))
imgLength = sys.getsizeof(bmpstr) ## bmpstr is the pixel data
prefix = str(imgLength) # message length
prefixSize = sys.getsizeof(prefix)
if prefixSize < 30:
prefix = ('0' * (30 - prefixSize)) + prefix
prefix = "5" + "1" + prefix ## BLOCK LOCATION
s.send(prefix.encode("UTF-8"))
totalSent = 0
while totalSent < imgLength:
totalSent += 4096
if (totalSent >= imgLength):
s.send(bmpstr[totalSent :])
break
else:
s.send(bmpstr[totalSent : totalSent + 4096])
Right now I simply run this twice, sending the prefix and pixel data the
same way. Its literally copy and paste. I don't close socket s, I use the
same connection for both images. I'm wondering if maybe that is my
problem? I am hoping to have a somewhat realtime transmission of data,
maybe 3-4 FPS, so I would like to do this as efficiently as possible.
Server Side:
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind(('localhost', 8888))
serversocket.listen(5)
transmission = clientsocket.recv(4096)
transmissionMetaData = decode_meta_data(transmission)
transmissionLength = transmissionMetaData[0]
blockX = transmissionMetaData[1]
blockY = transmissionMetaData[2]
while 1:
thisData = clientsocket.recv(4096)
data += thisData
if len(data) >= transmissionLength or not(thisData):
break
## rebuild the image...
## here is the problem, I am trying to receive the prefix data which will
contain
# the size of the second transmission. But for some reason this never gets
any data
# it works just fine when i do it above.
while 1:
thisData = clientsocket.recv(4096)
if thisData == "":
print "WTF"
if sys.getsizeof(transmission) >= 32:
transmissionMetaData = transmission[0:11]
break
transmissionMetaData = decode_meta_data(transmission)
transmissionLength = transmissionMetaData[0]
blockX = transmissionMetaData[1]
blockY = transmissionMetaData[2]
So I am either crashing when I call decode_meta_data because transmission
is empty (i.e. no data was received), or I am sitting printing out "WTF" a
million times. On the client side I print out the data that is being sent
so I know that it is is at least calling s.send(...). But the server is
not receiving anything. I am not sure what is going on, any ideas?
No comments:
Post a Comment