import socket
import json

print('Start')

serverSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, proto = 0)

serverSock.bind(('', 9090))
serverSock.listen(1)

class Message(object):
    def __init__(self, j):
        self.__dict__ = json.loads(j)
    def ToJson(self):
        string = str(self.__dict__)
        bytes = bytearray()
        bytes.extend(map(ord, string))
        return bytes

while True:
    clientSock, clientAddr = serverSock.accept()
    print('connected: ', clientAddr, '\n')

    while True:
        data = clientSock.recv(1024)    
        if not data:
            break
        message = Message(data)
        print('received: ', message.StringValue, message.IntegerValue)
        message.IntegerValue *= 2
        clientSock.sendall(message.ToJson())
        print('sended: ', message.StringValue, message.IntegerValue, '\n')

    clientSock.close()
    print('disconnected: ', clientAddr, '\n')

print('End')