예제 #1
0
파일: main.py 프로젝트: iftachshalev/bitLAN

# read config file
with open('config.json') as json_file:
    conf = json.load(json_file)

# init queue
from_sock_buff = Queue()
from_comp_buff = Queue()

# init communication
com = Communication(from_sock_buff, from_comp_buff, conf['port'],
                    conf['frame_size'])

# get user desision
my_ip = Communication.get_ip()
print('My ID is: ' + my_ip[my_ip.rfind('.') + 1:])
connect_id = input('Enter ID (or blank if server)  >> ')
if connect_id == '':
    print('Wait for connections...')
    com.listen()
    print('Connected by: ' + repr(com.addr))

    # For Test
    # Server pass all data to client as is
    if SELF_LOOP_FLAG:
        while True:
            from_comp_buff.put(from_sock_buff.get())
else:
    print('Connect to: ' + connect_id)
    server_ip = my_ip[:my_ip.rfind('.')] + '.' + connect_id