I have found one benign yet persistent problem with my socket client, it seems to hang and never receive a response from the server. Put differently, there is an indefinite wait for any response.
This only happens for cases where the server socket, has run say a minute or so method/function whose result is supposed to be returned to the client.
Put simply if you try to send plain text back and forth, this works fine, however making calls to a function that may need the client end to wait bit for a response cause it to hang.
Any help will be appreciated. Below is some code...thanks to @Robᵩ for providing an earlier solution that worked with text like input and response
client
import socket
s = socket.socket()
s.connect(("localhost",3000))
f=open ("tranmit.jpg", "rb")
l = f.read(1024)
while (l):
s.send(l)
l = f.read(1024)
s.shutdown(socket.SHUT_WR)
reply =s.recv(1024) # Feedback: would like the receive feedback from the server.
print reply
s.close()
server
import socket
import sys
s = socket.socket()
s.bind(("localhost",3000))
s.listen(10)
i=1
# def somefunction(x):
# ''' does some computationally semi intensive work, say last about 120s and returns a result for the client'''
while True:
sc, address = s.accept()
print address
f = open('transmit.jpg','wb') #open in binary
l = 1
while(l):
l = sc.recv(1024)
while (l):
f.write(l)
l = sc.recv(1024)
f.close()
result =somefunction('transmit.jpg') # does something with the image from the client
sc.send(str(result)) # Would like to send back a response
sc.close()
s.close()