-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreadClient.py
83 lines (67 loc) · 2 KB
/
threadClient.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /usr/bin/env python
import addressbook_pb2
import sys
import socket
#import SistemaLocacao_pb2
#Pra compilar o .proto:
#protoc --python_out=. addressbook.proto
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
# This function fills in a Person message based on user input.
def PromptForAddress(person):
person.id = int(raw_input("Enter person ID number: "))
person.name = raw_input("Enter name: ")
email = raw_input("Enter email address (blank for none): ")
if email != "":
person.email = email
while True:
number = raw_input("Enter a phone number (or leave blank to finish): ")
if number == "":
break
phone_number = person.phones.add()
phone_number.number = number
type = raw_input("Is this a mobile, home, or work phone? ")
if type == "mobile":
phone_number.type = addressbook_pb2.Person.MOBILE
elif type == "home":
phone_number.type = addressbook_pb2.Person.HOME
elif type == "work":
phone_number.type = addressbook_pb2.Person.WORK
else:
print("Unknown phone type; leaving as default value.")
def help():
print("Usage:", sys.argv[0])
sys.exit(-1)
if len(sys.argv) != 1:
help()
HOST = '127.0.0.1' # Endereco IP do Servidor
PORT = 16785 # Porta que o Servidor esta
tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
dest = (HOST, PORT)
tcp.connect(dest)
def menu():
print ('\n\n\n\n\n\n\n\n\n\n\nto exit, just type exit')
print ('\nThis is version 1.0\n')
print ('\nOnly insert operation is workin and not the way it should... \n')
print ('\n1.insert\n2.delete\n3.select\n')
msg = raw_input()
return msg
msg = menu()
while msg != 'exit':
address_book = addressbook_pb2.AddressBook()
if msg == '1':
tcp.send(b'1')
PromptForAddress(address_book.people.add())
tcp.send(address_book.SerializeToString())
print('\n\n\nEnviado!\n\n\n')
msg=''
if msg == '2':
tcp.send(b'2')
print('person ID: ')
id = raw_input()
tcp.send(b'')
msg=''
msg = menu()
tcp.close()