I'm trying to send a JSON File from a server to a client. The problem is, in the JSON File there is a special char 'Ć' and when i recieve the file in the client it's written 'F'. I'm not sure if i have to decode/encode it.
Here is the server:
import socket
sourcefile = 'TMS.JSON'
TCP_IP = '10.0.9.6' #IP of server!
TCP_PORT = 3487
s = socket.socket()
s.bind((TCP_IP, TCP_PORT))
s.listen(5)
print('DEBUG: Server listening....')
while True:
conn, addr = s.accept()
print('DEGUG: Got connection from', addr)
f = open(sourcefile, 'rb')
l = f.read(1024)
while (l):
conn.send(l)
l = f.read(1024)
f.close()
print('DEGUG: Done sending')
conn.close()
Here is the client:
import socket
import json
destinationfile = 'TMS_recieved.JSON'
TCP_IP = '10.0.9.6' #IP of server!
TCP_PORT = 3487
s = socket.socket()
s.connect((TCP_IP, TCP_PORT))
print('DEBUG: Recieving data....')
with open(destinationfile, 'wb') as f: #create JSON FILE
while True:
data = s.recv(1024)
if not data:
break
f.write(data)
f.close()
print('DEBUG: Successfully get the file')
s.close()
print('DEBUG: Connection closed')
with open(destinationfile, 'r') as f: #read JSON FILE
datastore = json.load(f)
print()
print('datastore['name'])
Can please someone help me? Thanks