Good morning,
I've a simple question.
I need a socket that allow a client to send an XML to a server. I've tried to send a simple string b'simple string just for example' and everything works fine, but when I try to send an XML (as binary) the server isn't able to write that down. I'll paste my code
Client
import socket
socket = socket.socket()
socket.connect(("localhost", 54610))
file = open(r"c:\shared\68118.xml", "rb")
stream = file.read(65536)
while stream:
socket.send(stream)
stream = file.read(65536) # tried with 1024, 2048
socket.close()
Server
import socket
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('', 54610)
socket.bind(server_address)
socket.listen(1)
while True:
inbound_stream, address = socket.accept()
print(address)
counter = 1
file = open(r'c:\shared\68118_' + str(counter) + '.xml', 'wb') # binary
counter += 1
while(True):
stream = inbound_stream.recv(65536)
while stream:
file.write(stream)
stream = inbound_stream.recv(65536) # tried with 1024, 2048
file.close()
inbound_stream.close()
socket.close() # TODO NOT REACHABLE
the output file is 68118_1.xml 0Kb with nothing inside
What I'm doing wrong?
Thank you in advance