コード例 #1
0
ファイル: client.py プロジェクト: mfbsouza/ReliableUDP
#         next_seq += 1
#         s.send_segment(connection_request, rcv_base, (SERVER_HOST, SERVER_PORT))

#         # wait for ack and new socket port number
#         segment, client_addr = s.receive_segment()
#         if segment.syn == '1' and segment.ack_number != -1:
#             print('received SYN_ACK\n')

#         state = "established"
#     elif state == "established":
#         s.send_ack((SERVER_HOST, SERVER_PORT))

#         state = "break"
#     elif state == "break":
#         state = "menu"
#         break

while True:
    if state == "menu":
        # request menu
        request_msg = '0'
        s.send_message(request_msg, (SERVER_HOST, SERVER_PORT))

        # receive menu
        menu, addr = s.receive_message()
        print(menu)

        state = "break"

    elif state == "break":
        break
コード例 #2
0
#         if segment.syn == '1':
#             # create new socket
#             tube_socket_port = SELF_PORT+1  # make port number random and check if it already exists
#             tube_socket = MySocket(AF_INET, SOCK_DGRAM)
#             tube_socket.bind((SELF_HOST, tube_socket_port))

#             # # send ACK with socket port number
#             # syn_ack_data = str(tube_socket_port)
#             # syn_ack = Segment(next_seq, rcv_base, syn='1', data=syn_ack_data)
#             # next_seq += 1
#             # s.send_segment(syn_ack, rcv_base, client_addr)

#         state = "syn_rcvd"
#     elif state == "syn_rcvd":
#         # wait for ACK
#         segment, client_addr = s.receive_segment()
#         print('received ACK\n')

#         state = "break"
#     elif state == "break":
#         break


while True:
    segment, client_addr = s.receive_message()

    if segment == '0':    # send menu
        s.send_message(MENU, client_addr)

        print('Sent menu')