Hello, I'm struggling with following error:
"socket.error: [10053] 'Software caused connection abort'"
Traceback (most recent call last): ... self.send(json.dumps([0x02, subItems])+"\n") ... sent = self.handler.send(data) socket.error: [Errno 10053]
I established server properely, I can connect to it, send "hello" message, then I can send one more 0x1 type message. Next client actions are not being seen by server side. Client program throws above socket.error .
import SocketServer
class ThreadedTCPRequestHandler(SocketServer.StreamRequestHandler):
def handle(self):
#data = json.loads(self.request.recv(1024))
if(self.request in subengine.sub.get_all_sub()):
pass
else:
#login = json.loads(self.request.recv(1024))
login = json.loads(self.rfile.readline().strip())
logging.debug("User : %s connected" % login )
data = json.loads(self.rfile.readline().strip())
if(data[0]==0x1): # subscribe
logging.info("subscribe message received, from %d" % self.request.fileno())
logging.info("symbols to subscribe: %s" % data[1])
elif (data[0] == 0x2): # unsubscribe
logging.info("unsubscribe message received")
else:
pass
# def finish(self):
# logging.info("terminating connection")
class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
pass
server = ThreadedTCPServer(('localhost',5555), ThreadedTCPRequestHandler)
server_thread = threading.Thread(target=server.serve_forever)
server_thread.setDaemon(True)
server_thread.start()
client side code example:
class Client:
handler = None
def __init__(self, uname = '', host = 'localhost', port = 0, sock = None):
if sock is None:
self.handler = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.host = host
self.port = port
self.uname = uname
def feed_conection(self):
self.handler.connect((self.host, self.port))
if(self.handler != 0):
self.handler.send(json.dumps(self.uname)+"\n")
else:
print ("Nie udalo sie polaczyc")
def sub(self, subItems):
self.send(json.dumps([0x01, subItems])+"\n")
def unsub(self, subItems):
self.send(json.dumps([0x02, subItems])+"\n")
def send(self, data):
data_len = len(data)
total_sent = 0
while(total_sent < data_len):
sent = self.handler.send(data)
if not sent:
break
data = data[sent:]
total_sent += sent